مۆدیوول:scripts: جیاوازیی نێوان پێداچوونەوەکان

ناوەڕۆکی سڕاو ناوەڕۆکی زیادکراو
نوێکردنەوە (بەپێی ویکیفەرھەنگی ئینگلیزی)
No edit summary
تاگ: گەڕێندراوە
ھێڵی ١:
local export = {}
 
local Script = {}
 
Line ٢٩ ⟶ ٣٠:
end
 
--[==[Returns the parent of the script. Example: {{code|lua|"Latn"}} for {{code|lua|"LatinxLatnx"}} and {{code|lua|"Arab"}} for {{code|lua|"fa-Arab"}}. It returns {{code|lua|"top"}} for scripts without a parent, like {{code|lua|"Latn"}}, {{code|lua|"Grek"}}, etc.]==]
function Script:getParent()
return self._rawData.parent
Line ١٢٤ ⟶ ١٢٥:
-- Due to the number of Chinese characters, a different determination method is used when differentiating between traditional ("Hant") and simplified ("Hans") Chinese.
elseif self:getCode() == "Hant" or self:getCode() == "Hans" then
local charData, num = self:getCode() == "Hant" and mw.loadDatarequire("Module:zh/data/ts/serialized")[1] or mw.loadDatarequire("Module:zh/data/st/serialized")[1], 0
charData = charData:sub(1, charData:len() / 2)
for char in text:gmatch("[\194-\244][\128-\191]*") do
if charData:find(char) then
num = num + 1 end
end
end
return num
Line ١٤٥ ⟶ ١٤٩:
function Script:isTransliterated()
return self._rawData.translit ~= false
end
 
--[==[Returns true if the script is (sometimes) sorted by scraping page content, meaning that it is sensitive to changes in capitalization during sorting.]==]
function Script:sortByScraping()
return not not self._rawData.sort_by_scraping
end
 
Line ٢٤٢ ⟶ ٢٥١:
 
Script.__index = Script
 
function export.makeObject(code, data, useRequire)
return data and setmetatable({_rawData = data, _code = code}, Script) or nil
end
 
-- Track scripts with anomalous names.
local scriptsToTrack = {
-- scripts already renamed
["IPAchar"] = true,
["musical"] = true,
["Ruminumerals"] = true,
["polytonic"] = true,
-- scripts not yet renamed
["Latinx"] = true,
}
 
-- Temporary aliases from canonicalized names to (existing) anomalous names. Once we have converted everything we will
-- rename the scripts and remove the alias code.
local scriptAliases = {
-- scripts already renamed; we now alias the old names to the new ones
["IPAchar"] = "Ipach",
["musical"] = "Music",
["Ruminumerals"] = "Rumin",
["polytonic"] = "Polyt",
["Latinx"] = "Latnx",
}
 
--[==[Finds the script whose code matches the one provided. If it exists, it returns a {{code|lua|Script}} object representing the script. Otherwise, it returns {{code|lua|nil}}, unless <span class="n">paramForError</span> is given, in which case an error is generated. If <code class="n">paramForError</code> is {{code|lua|true}}, a generic error message mentioning the bad code is generated; otherwise <code class="n">paramForError</code> should be a string or number specifying the parameter that the code came from, and this parameter will be mentioned in the error message along with the bad code.]==]
function export.getByCode(code, paramForError, disallowNil, useRequire)
if code == nil and not disallowNil then
return nil
end
if scriptsToTrack[code == "IPAchar"] then
require("Module:debug/track")("IPAcharscripts/" .. code)
end
code = scriptAliases[code] or code
local retval = export.makeObject(code, mw.loadData("Module:scripts/data")[code])
local data
if not codeuseRequire then
local code data = mw.loadDatarequire("Module:scripts/by namedata")[namecode]
else
local retval data = export.makeObject(code, mw.loadData("Module:scripts/data")[code])
end
local retval = export.makeObject(code, data, useRequire)
if not retval and paramForError then
require("Module:languages/error")(code, paramForError, "script code", nil, "not real lang")
end
return retval
end
 
function export.getByCanonicalName(name, useRequire)
local code
local code = mw.loadData("Module:scripts/by name")[name]
if useRequire then
code = require("Module:scripts/by name")[name]
if not code then
else
return nil
code = mw.loadData("Module:scripts/by name")[name]
end
return export.makeObjectgetByCode(code, mw.loadData("Module:scripts/data")[code]nil, nil, useRequire)
end