မေႃႇၵျူး:languages: လွင်ႈပႅၵ်ႇပိူင်ႈ ၼႂ်းၵႄႈ လွင်ႈၶူၼ်ႉၶႆႈ
Content deleted Content added
Saimawnkham (ဢုပ်ႇဢူဝ်း) ၵေႃႉ ၶိုၼ်ၶိုၼ်း လွင်ႈၶူၼ်ႉၶႆႈ 92501 Tags: Undo Reverted |
No edit summary Tag: Reverted |
||
ထႅဝ် 1:
local export = {}
--[=[ This function checks for things that could plausibly be a language code:
two or three lowercase letters, two or three groups of three lowercase
letters with hyphens between them. If such a pattern is not found,
it is likely the editor simply forgot to enter a language code. ]=]
function export.err(langCode, param, text, template_tag)
local ordinals = {
"first", "second", "third", "fourth", "fifth", "sixth",
"seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth",
"thirteenth", "fourteenth", "fifteenth", "sixteenth", "seventeenth",
"eighteenth", "nineteenth", "twentieth"
}
text = text or "language code"
if not template_tag then
template_tag = ""
else
if type(template_tag) ~= "string" then
template_tag = template_tag()
end
template_tag = " (Original template: " .. template_tag .. ")"
end
local paramType = type(param)
if paramType == "number" then
ordinal = ordinals[param]
param = ordinal .. ' parameter'
elseif paramType == "string" then
param = 'parameter "' .. param .. '"'
else
error("The parameter name is "
.. (paramType == "table" and "a table" or tostring(param))
.. ", but it should be a number or a string." .. template_tag, 2)
end
-- Can use string.find because language codes only contain ASCII.
if not langCode or langCode == "" then
error("The " .. param .. " (" .. text .. ") is missing." .. template_tag, 2)
elseif langCode:find("^%l%l%l?$")
or langCode:find("^%l%l%l%-%l%l%l$")
or langCode:find("^%l%l%l%-%l%l%l%-%l%l%l$") then
error("The " .. text .. " \"" .. langCode .. "\" is not valid." .. template_tag, 2)
else
error("Please enter a " .. text .. " in the " .. param .. "." .. template_tag, 2)
end
end
local function do_entry_name_or_sort_key_replacements(text, replacements)
Line 10 ⟶ 57:
if replacements.remove_diacritics then
text = mw.ustring.toNFD(text)
text = mw.ustring.gsub(text,
Line 22 ⟶ 62:
'')
text = mw.ustring.toNFC(text)
end
Line 43 ⟶ 76:
function Language:getCanonicalName()
return self._rawData[1] or self._rawData.canonicalName
end
function Language:getOtherNames(onlyOtherNames)
if onlyOtherNames then
return self._rawData.otherNames or {}
end
-- Combine otherNames, aliases and varieties. First try to optimize and not create any
-- new memory. This is possible if exactly one of the three exist, and if it's `varieties`,
-- there are no nested lists in `varieties`.
if self._rawData.otherNames and not self._rawData.aliases and not self._rawData.varieties then
return self._rawData.otherNames
elseif self._rawData.aliases and not self._rawData.otherNames and not self._rawData.varieties then
return self._rawData.aliases
elseif self._rawData.varieties and not self._rawData.otherNames and not self._rawData.aliases then
local saw_table = false
for _, name in ipairs(self._rawData.varieties) do
if type(name) == "table" then
saw_table = true
break
end
end
if not saw_table then
return self._rawData.varieties
end
end
-- Have to do it the "hard way".
local ret = {}
if self._rawData.otherNames then
for _, name in ipairs(self._rawData.otherNames) do
table.insert(ret, name)
end
end
if self._rawData.aliases then
for _, name in ipairs(self._rawData.aliases) do
table.insert(ret, name)
end
end
if self._rawData.varieties then
for _, name in ipairs(self._rawData.varieties) do
if type(name) == "table" then
for _, n in ipairs(name) do
table.insert(ret, n)
end
else
table.insert(ret, name)
end
end
end
return ret
end
function Language:getAliases()
return self._rawData.aliases or {}
end
function Language:getVarieties(flatten)
if self._rawData.varieties then
-- If flattening not requested, just return them.
if not flatten then
return self._rawData.varieties
end
-- Check if no nested table; if so, just return the result.
local saw_table = false
for _, name in ipairs(self._rawData.varieties) do
if type(name) == "table" then
saw_table = true
break
end
end
if not saw_table then
return self._rawData.varieties
end
-- At this point, we need to flatten the varieties.
local ret = {}
for _, name in ipairs(self._rawData.varieties) do
if type(name) == "table" then
for _, n in ipairs(name) do
table.insert(ret, n)
end
else
table.insert(ret, name)
end
end
return ret
else
return {}
end
end
Line 94 ⟶ 195:
return self._wikipedia_article
elseif self:getWikidataItem() and mw.wikibase then
self._wikipedia_article = mw.wikibase.sitelink(self:getWikidataItem(),
end
if not self._wikipedia_article then
Line 103 ⟶ 204:
function Language:makeWikipediaLink()
return "[[w:" .. self:getWikipediaArticle() .. "|" .. self:
end
function Language:getWikidataItem()
end
Line 121 ⟶ 216:
self._scriptObjects = {}
for _, sc in ipairs(self
table.insert(self._scriptObjects, m_scripts.getByCode(sc))
end
Line 130 ⟶ 225:
function Language:getScriptCodes()
return self._rawData.scripts
end
Line 237 ⟶ 332:
function Language:makeEntryName(text
text = mw.ustring.match(text, "^[¿¡]?(.-[^%s%p].-)%s*[؟?!;՛՜ ՞ ՟?!︖︕।॥။၊་།]?$") or text
if self:getCode() == "ar" then
local U = mw.ustring.char
local taTwiil = U(0x640)
local waSla = U(0x671)
-- diacritics ordinarily removed by entry_name replacements
local Arabic_diacritics = U(0x64B, 0x64C, 0x64D, 0x64E, 0x64F, 0x650, 0x651, 0x652, 0x670)
if text == waSla or mw.ustring.find(text, "^" .. taTwiil .. "?[" .. Arabic_diacritics .. "]" .. "$") then
return text
end
end
if type(self._rawData.entry_name) == "table" then
text = do_entry_name_or_sort_key_replacements(text, self._rawData.entry_name)
end
Line 251 ⟶ 355:
-- Add to data tables?
local has_dotted_undotted_i = {
["az"] = true,
["crh"] = true,
["gag"] = true,
["kaa"] = true,
["tt"] = true,
["tr"] = true,
["zza"] = true,
}
function Language:makeSortKey(name, sc)
if has_dotted_undotted_i[self:getCode()] then
name = name:gsub("I", "ı")
end
name = mw.ustring.lower(name)
-- Remove initial hyphens and *
local hyphens_regex = "^[-־ـ*]+(.)"
name = mw.ustring.gsub(name, hyphens_regex, "%1")
-- If there
if type(self._rawData.sort_key) == "
name = do_entry_name_or_sort_key_replacements(name, self._rawData.sort_key)
elseif type(self._rawData.sort_key) == "string" then
name = require("Module:" .. self._rawData.sort_key).makeSortKey(name, self:getCode(), sc and sc:getCode())
end
Line 298 ⟶ 388:
name = mw.ustring.gsub(name, "[()]+(.)", "%1")
if has_dotted_undotted_i[self:getCode()] then
name = name:gsub("i", "İ")
end
return mw.ustring.upper(name)
end
Line 350 ⟶ 444:
ancestors = self._rawData.ancestors,
canonicalName = self:getCanonicalName(),
categoryName = self:getCategoryName(
code = self._code,
entryNamePatterns = entryNamePatterns,
entryNameRemoveDiacritics = entryNameRemoveDiacritics,
family = self._rawData[3] or self._rawData.family,
otherNames = self:getOtherNames(
aliases = self:getAliases(),
varieties = self:getVarieties(),
scripts = self._rawData.scripts
type = self:getType(),
wikimediaLanguages = self._rawData.wikimedia_codes,
Line 368 ⟶ 462:
-- Do NOT use
-- All uses should be pre-approved on the talk page!
function Language:getRawData()
return self._rawData
end
Language.__index = Language
Line 412 ⟶ 487:
local function getRawLanguageData(code)
local modulename = export.getDataModuleName(code)
return modulename and mw.loadData("
end
Line 458 ⟶ 516:
end
if not retval and paramForError then
local codetext = nil
if allowEtymLang and allowFamily then
codetext = "language, etymology language or family code"
elseif allowEtymLang then
codetext = "language or etymology language code"
elseif allowFamily then
codetext = "language or family code"
else
codetext = "language code"
end
if paramForError == true then
error("The " .. codetext .. " \"" .. code .. "\" is not valid.")
else
export.err(code, paramForError, codetext)
end
end
return retval
Line 470 ⟶ 542:
if not code then
if errorIfInvalid then
error("The language name \"" .. name .. "\" is not valid
else
return nil
Line 485 ⟶ 557:
local retval = code and export.makeObject(code, getRawLanguageData(code)) or nil
if not retval and allowEtymLang then
retval = require("Module:etymology languages").getByCanonicalName(
end
if not retval and allowFamily then
retval = require("Module:families").getByCanonicalName(code)
end
if not retval and errorIfInvalid then
local text
if allowEtymLang and allowFamily then
text = "language, etymology language or family name"
elseif allowEtymLang then
text = "language or etymology language name"
elseif allowFamily then
text = "language or family name"
else
text = "language name"
end
error("The " .. text .. " \"" .. name .. "\" is not valid.")
end
return retval
end
function export.iterateAll()
mw.incrementExpensiveFunctionCount()
local m_data = mw.loadData("Module:languages/data/all")
local func, t, var = pairs(m_data)
return function()
local code, data = func(t, var)
return export.makeObject(code, data)
end
end
Line 509 ⟶ 600:
return lang
end
|