<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://academia.la/w/index.php?action=history&amp;feed=atom&amp;title=Module%3Ascripts</id>
	<title>Module:scripts - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://academia.la/w/index.php?action=history&amp;feed=atom&amp;title=Module%3Ascripts"/>
	<link rel="alternate" type="text/html" href="https://academia.la/w/index.php?title=Module:scripts&amp;action=history"/>
	<updated>2026-04-18T01:26:59Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.40.0</generator>
	<entry>
		<id>https://academia.la/w/index.php?title=Module:scripts&amp;diff=1503&amp;oldid=prev</id>
		<title>Jācōbus: Created page with &quot;local export = {} local Script = {}  function Script:getCode() 	return self._code end   function Script:getCanonicalName() 	return self._rawData.canonicalName end   function Script:getDisplayForm() 	return self:getCategoryName(&quot;nocap&quot;) end   function Script:getOtherNames(onlyOtherNames) 	return require(&quot;Module:language-like&quot;).getOtherNames(self, onlyOtherNames) end   function Script:getAliases() 	return self._rawData.aliases or {} end   function Script:getVarieties(flatt...&quot;</title>
		<link rel="alternate" type="text/html" href="https://academia.la/w/index.php?title=Module:scripts&amp;diff=1503&amp;oldid=prev"/>
		<updated>2023-02-07T23:07:06Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;local export = {} local Script = {}  function Script:getCode() 	return self._code end   function Script:getCanonicalName() 	return self._rawData.canonicalName end   function Script:getDisplayForm() 	return self:getCategoryName(&amp;quot;nocap&amp;quot;) end   function Script:getOtherNames(onlyOtherNames) 	return require(&amp;quot;Module:language-like&amp;quot;).getOtherNames(self, onlyOtherNames) end   function Script:getAliases() 	return self._rawData.aliases or {} end   function Script:getVarieties(flatt...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;local export = {}&lt;br /&gt;
local Script = {}&lt;br /&gt;
&lt;br /&gt;
function Script:getCode()&lt;br /&gt;
	return self._code&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
function Script:getCanonicalName()&lt;br /&gt;
	return self._rawData.canonicalName&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
function Script:getDisplayForm()&lt;br /&gt;
	return self:getCategoryName(&amp;quot;nocap&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
function Script:getOtherNames(onlyOtherNames)&lt;br /&gt;
	return require(&amp;quot;Module:language-like&amp;quot;).getOtherNames(self, onlyOtherNames)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
function Script:getAliases()&lt;br /&gt;
	return self._rawData.aliases or {}&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
function Script:getVarieties(flatten)&lt;br /&gt;
	return require(&amp;quot;Module:language-like&amp;quot;).getVarieties(self, flatten)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
function Script:getParent()&lt;br /&gt;
	return self._rawData.parent&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
function Script:getSystems()&lt;br /&gt;
	if not self._systemObjects then&lt;br /&gt;
		local m_systems = require(&amp;quot;Module:writing systems&amp;quot;)&lt;br /&gt;
		self._systemObjects = {}&lt;br /&gt;
		&lt;br /&gt;
		for _, sys in ipairs(self._rawData.systems or {}) do&lt;br /&gt;
			table.insert(self._systemObjects, m_systems.getByCode(sys))&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	return self._systemObjects&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--function Script:getAllNames()&lt;br /&gt;
--	return self._rawData.names&lt;br /&gt;
--end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
function Script:getType()&lt;br /&gt;
	return &amp;quot;script&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
function Script:getCategoryName(nocap)&lt;br /&gt;
	local name = self._rawData.canonicalName&lt;br /&gt;
	&lt;br /&gt;
	-- If the name already has &amp;quot;code&amp;quot; or &amp;quot;semaphore&amp;quot; in it, don't add it.&lt;br /&gt;
	-- No names contain &amp;quot;script&amp;quot;.&lt;br /&gt;
	if not name:find(&amp;quot;[Cc]ode$&amp;quot;) and not name:find(&amp;quot;[Ss]emaphore$&amp;quot;) then&lt;br /&gt;
		name = name .. &amp;quot; script&amp;quot;&lt;br /&gt;
	end&lt;br /&gt;
	if not nocap then&lt;br /&gt;
		name = mw.getContentLanguage():ucfirst(name)&lt;br /&gt;
	end&lt;br /&gt;
	return name&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
function Script:makeCategoryLink()&lt;br /&gt;
	return &amp;quot;[[:Category:&amp;quot; .. self:getCategoryName() .. &amp;quot;|&amp;quot; .. self:getDisplayForm() .. &amp;quot;]]&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
function Script:getWikipediaArticle()&lt;br /&gt;
	return self._rawData.wikipedia_article or self:getCategoryName()&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
function Script:getCharacters()&lt;br /&gt;
	if self._rawData.characters then&lt;br /&gt;
		return self._rawData.characters&lt;br /&gt;
	else&lt;br /&gt;
		return nil&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
function Script:hasCapitalization()&lt;br /&gt;
	return not not self._rawData.capitalized&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
function Script:countCharacters(text)&lt;br /&gt;
	if not self._rawData.characters then&lt;br /&gt;
		return 0&lt;br /&gt;
	-- Due to the number of Chinese characters, a different determination method is used when differentiating between traditional (&amp;quot;Hant&amp;quot;) and simplified (&amp;quot;Hans&amp;quot;) Chinese.&lt;br /&gt;
	elseif self._code == &amp;quot;Hant&amp;quot; then&lt;br /&gt;
		local u = mw.ustring.char&lt;br /&gt;
		local ts_data = mw.loadData(&amp;quot;Module:zh/data/ts&amp;quot;)&lt;br /&gt;
		for codepoint in mw.ustring.gcodepoint(text) do&lt;br /&gt;
			if ts_data.ts[u(codepoint)] then return 1 end&lt;br /&gt;
		end&lt;br /&gt;
		return 0&lt;br /&gt;
	elseif self._code == &amp;quot;Hans&amp;quot; then&lt;br /&gt;
		local u = mw.ustring.char&lt;br /&gt;
		local st_data = mw.loadData(&amp;quot;Module:zh/data/st&amp;quot;)&lt;br /&gt;
		for codepoint in mw.ustring.gcodepoint(text) do&lt;br /&gt;
			if st_data.st[u(codepoint)] then return 1 end&lt;br /&gt;
		end&lt;br /&gt;
		return 0&lt;br /&gt;
	else&lt;br /&gt;
		local _, num = mw.ustring.gsub(text, &amp;quot;[&amp;quot; .. self._rawData.characters .. &amp;quot;]&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
		return num&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
function Script:getDirection()&lt;br /&gt;
	local direction = self._rawData.direction&lt;br /&gt;
	if not direction then&lt;br /&gt;
		return nil&lt;br /&gt;
	else&lt;br /&gt;
		return direction&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
function Script:getRawData()&lt;br /&gt;
	return self._rawData&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
-- Return true if the script requires fixes to Unciode normalization under certain circumstances.&lt;br /&gt;
function Script:hasNormalizationFixes()&lt;br /&gt;
	return not not self._rawData.normalizationFixes&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
-- Corrects discouraged sequences of Unicode characters to the encouraged equivalents.&lt;br /&gt;
function Script:fixDiscouragedSequences(text)&lt;br /&gt;
	if self:hasNormalizationFixes() and self._rawData.normalizationFixes.from then&lt;br /&gt;
		local gsub&lt;br /&gt;
		for i, from in ipairs(self._rawData.normalizationFixes.from) do&lt;br /&gt;
			-- Most of the time, it's faster to check whether mw.ustring.gsub is actually necessary before using it, as it's a lot slower.&lt;br /&gt;
			if from:match(&amp;quot;[%%.[%]*+%-?]&amp;quot;) then gsub = mw.ustring.gsub else gsub = string.gsub end&lt;br /&gt;
			text = gsub(text, from, self._rawData.normalizationFixes.to[i] or &amp;quot;&amp;quot;)&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	return text&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
-- Implements a modified form of Unicode normalization, which fixes issues caused by MediaWiki, and for instances where there are identified deficiencies in the default Unicode combining classes.&lt;br /&gt;
local function fixNormalization(text, self)&lt;br /&gt;
	-- Convert special pagename characters generated by {{PAGENAME}} etc. back to their normal forms.&lt;br /&gt;
	if text:match(&amp;quot;&amp;amp;#&amp;quot;) then&lt;br /&gt;
		text = text:gsub(&amp;quot;&amp;amp;#34;&amp;quot;, &amp;quot;\&amp;quot;&amp;quot;):gsub(&amp;quot;&amp;amp;#38;&amp;quot;, &amp;quot;&amp;amp;&amp;quot;):gsub(&amp;quot;&amp;amp;#39;&amp;quot;, &amp;quot;'&amp;quot;)&lt;br /&gt;
	end&lt;br /&gt;
	-- Fixes to Unicode combining class.&lt;br /&gt;
	if self:hasNormalizationFixes() and self._rawData.normalizationFixes.combiningClasses then&lt;br /&gt;
		local combiningClassFixes = self._rawData.normalizationFixes.combiningClasses&lt;br /&gt;
		local charsToFix = table.concat(require(&amp;quot;Module:table&amp;quot;).keysToList(combiningClassFixes))&lt;br /&gt;
		if mw.ustring.match(text, &amp;quot;[&amp;quot; .. charsToFix .. &amp;quot;]&amp;quot;) then&lt;br /&gt;
			local gsub, codepoint, u = mw.ustring.gsub, mw.ustring.codepoint, mw.ustring.char&lt;br /&gt;
			-- Obtain the list of default combining classes.&lt;br /&gt;
			local combiningClasses = mw.loadData(&amp;quot;Module:scripts/data/combiningClasses&amp;quot;)&lt;br /&gt;
			-- For each character that needs fixing, find all characters with combining classes equal to or lower than its default class, but greater than its new class (i.e. intermediary characters).&lt;br /&gt;
			for charToFix, newCombiningClass in pairs(combiningClassFixes) do&lt;br /&gt;
				local intermediaryChars = {}&lt;br /&gt;
				for character, combiningClass in pairs(combiningClasses) do&lt;br /&gt;
					if newCombiningClass &amp;lt; combiningClass and combiningClass &amp;lt;= combiningClasses[codepoint(charToFix)] then&lt;br /&gt;
						table.insert(intermediaryChars, u(character))&lt;br /&gt;
					end&lt;br /&gt;
				end&lt;br /&gt;
				-- Swap the character with any intermediary characters that are immediately before it.&lt;br /&gt;
				text = gsub(text, &amp;quot;([&amp;quot; .. table.concat(intermediaryChars) .. &amp;quot;]+)(&amp;quot; .. charToFix .. &amp;quot;)&amp;quot;, &amp;quot;%2%1&amp;quot;)&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	return text&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function Script:toFixedNFC(text)&lt;br /&gt;
	return fixNormalization(mw.ustring.toNFC(text), self)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function Script:toFixedNFD(text)&lt;br /&gt;
	return fixNormalization(mw.ustring.toNFD(text), self)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function Script:toFixedNFKC(text)&lt;br /&gt;
	return fixNormalization(mw.ustring.toNFKC(text), self)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function Script:toFixedNFKD(text)&lt;br /&gt;
	return fixNormalization(mw.ustring.toNFKD(text), self)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
function Script:toJSON()&lt;br /&gt;
	local ret = {&lt;br /&gt;
		canonicalName = self:getCanonicalName(),&lt;br /&gt;
		categoryName = self:getCategoryName(&amp;quot;nocap&amp;quot;),&lt;br /&gt;
		code = self._code,&lt;br /&gt;
		otherNames = self:getOtherNames(true),&lt;br /&gt;
		aliases = self:getAliases(),&lt;br /&gt;
		varieties = self:getVarieties(),&lt;br /&gt;
		type = self:getType(),&lt;br /&gt;
		direction = self:getDirection(),&lt;br /&gt;
		characters = self:getCharacters(),&lt;br /&gt;
		parent = self:getParent(),&lt;br /&gt;
		systems = self._rawData.systems or {},&lt;br /&gt;
		wikipediaArticle = self._rawData.wikipedia_article,&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	return require(&amp;quot;Module:JSON&amp;quot;).toJSON(ret)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Script.__index = Script&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
function export.makeObject(code, data)&lt;br /&gt;
	return data and setmetatable({ _rawData = data, _code = code, _type = &amp;quot;script object&amp;quot; }, Script) or nil&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
function export.getByCode(code, paramForError, disallowNil)&lt;br /&gt;
	if code == nil and not disallowNil then&lt;br /&gt;
		return nil&lt;br /&gt;
	end&lt;br /&gt;
	if code == &amp;quot;IPAchar&amp;quot; then&lt;br /&gt;
		require(&amp;quot;Module:debug/track&amp;quot;)(&amp;quot;IPAchar&amp;quot;)&lt;br /&gt;
	end&lt;br /&gt;
	local retval = export.makeObject(code, mw.loadData(&amp;quot;Module:scripts/data&amp;quot;)[code])&lt;br /&gt;
	if not retval and paramForError then&lt;br /&gt;
		require(&amp;quot;Module:languages/error&amp;quot;)(code, paramForError, &amp;quot;script code&amp;quot;, nil, &amp;quot;not real lang&amp;quot;)&lt;br /&gt;
	end&lt;br /&gt;
	return retval&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
function export.getByCanonicalName(name)&lt;br /&gt;
	local code = mw.loadData(&amp;quot;Module:scripts/by name&amp;quot;)[name]&lt;br /&gt;
	&lt;br /&gt;
	if not code then&lt;br /&gt;
		return nil&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	return export.makeObject(code, mw.loadData(&amp;quot;Module:scripts/data&amp;quot;)[code])&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Find the best script to use, based on the characters of a string.&lt;br /&gt;
-- If forceDetect is set, run the detection algorithm even if there's only one&lt;br /&gt;
-- possible script; in that case, if the text isn't in the script, the return&lt;br /&gt;
-- value will be None.&lt;br /&gt;
function export.findBestScript(text, lang, forceDetect)&lt;br /&gt;
	if not text or not lang or not lang.getScripts then&lt;br /&gt;
		return export.getByCode(&amp;quot;None&amp;quot;)&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	local scripts = lang:getScripts()&lt;br /&gt;
	if not scripts[2] and not forceDetect then&lt;br /&gt;
		return scripts[1]&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	return require(&amp;quot;Module:scripts/findBestScript&amp;quot;)(export, text, lang, scripts, forceDetect)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[=[&lt;br /&gt;
	Takes a codepoint or a character and finds the script code (if any) that is&lt;br /&gt;
	appropriate for it based on the codepoint, using the data module&lt;br /&gt;
	[[Module:scripts/recognition data]]. The data module was generated from the&lt;br /&gt;
	patterns in [[Module:scripts/data]] using [[Module:User:Erutuon/script recognition]].&lt;br /&gt;
&lt;br /&gt;
	Converts the character to a codepoint. Returns a script code if the codepoint&lt;br /&gt;
	is in the list of individual characters, or if it is in one of the defined&lt;br /&gt;
	ranges in the 4096-character block that it belongs to, else returns &amp;quot;None&amp;quot;.&lt;br /&gt;
]=]&lt;br /&gt;
function export.charToScript(char)&lt;br /&gt;
	return require(&amp;quot;Module:scripts/charToScript&amp;quot;).charToScript(char)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
function export.findBestScriptWithoutLang(text)&lt;br /&gt;
	return require(&amp;quot;Module:scripts/charToScript&amp;quot;).findBestScriptWithoutLang(text)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return export&lt;/div&gt;</summary>
		<author><name>Jācōbus</name></author>
	</entry>
</feed>