Modul:etymology languages: Ferqê çımraviyarnayışan
Content deleted Content added
Pela vıraziyê, 'local export = {} local EtymologyLanguage = {} function EtymologyLanguage:getCode() return self._code end function EtymologyLanguage:getCanonicalName() return s...' bıvinê |
No edit summary Etiket: Peyser gêriya |
||
Rêza 1: | Rêza 1: | ||
local export = {} |
local export = {} |
||
function export.makeObject(code) |
|||
local EtymologyLanguage = {} |
|||
local data = mw.loadData("Module:etymology languages/data")[code] |
|||
code = data and data.main_code or code |
|||
function EtymologyLanguage:getCode() |
|||
if not data then |
|||
return self._code |
|||
return nil |
|||
end |
|||
end |
|||
local EtymologyLanguage = require("Module:languages").getByCode(data[5], nil, true, true) |
|||
return self._rawData.canonicalName |
|||
local familyCode |
|||
end |
|||
if EtymologyLanguage:hasType("family") then |
|||
-- Substrates are treated as child languages of "undetermined". |
|||
if EtymologyLanguage:getCode() == "qfa-sub" then |
|||
EtymologyLanguage = require("Module:languages").getByCode("und") |
|||
return self:getCanonicalName() |
|||
end |
|||
function EtymologyLanguage:getOtherNames(onlyOtherNames) |
|||
return require("Module:language-like").getOtherNames(self, onlyOtherNames) |
|||
end |
|||
function EtymologyLanguage:getAliases() |
|||
return self._rawData.aliases or {} |
|||
end |
|||
function EtymologyLanguage:getVarieties(flatten) |
|||
return require("Module:language-like").getVarieties(self, flatten) |
|||
end |
|||
--function EtymologyLanguage:getAllNames() |
|||
-- return self._rawData.names |
|||
--end |
|||
function EtymologyLanguage:getCategoryName() |
|||
return self:getCanonicalName() |
|||
end |
|||
function EtymologyLanguage:makeCategoryLink() |
|||
return "[[:Category:" .. self:getCategoryName() .. "|" .. self:getCanonicalName() .. "]]" |
|||
end |
|||
function EtymologyLanguage:getType() |
|||
return "etymology language" |
|||
end |
|||
function EtymologyLanguage:getParentCode() |
|||
return self._rawData.parent |
|||
end |
|||
function EtymologyLanguage:getAncestors() |
|||
if not self._ancestorObjects then |
|||
self._ancestorObjects = {} |
|||
for _, ancestor in ipairs(self._rawData.ancestors or {}) do |
|||
table.insert(self._ancestorObjects, export.getByCode(ancestor) or require("Module:languages").getByCode(ancestor)) |
|||
end |
end |
||
-- True etymology-only families (e.g. "ira-old") still need to grab the family code. |
|||
familyCode = data[5] |
|||
end |
end |
||
-- Delete cached _type table to prevent the new object's hasType method from finding it via the metatable, as it only includes the parent's types. |
|||
EtymologyLanguage._type = nil |
|||
if not EtymologyLanguage then |
|||
return self._ancestorObjects |
|||
return nil |
|||
end |
|||
end |
|||
function EtymologyLanguage:getWikidataItem() |
|||
return self._rawData.wikidata_item |
|||
end |
|||
function EtymologyLanguage:getWikipediaArticle() |
|||
return self._rawData.wikipedia_article or |
|||
(self:getWikidataItem() and mw.wikibase and |
|||
mw.wikibase.sitelink(self:getWikidataItem(), 'enwiki')) or |
|||
self._rawData.canonicalName |
|||
end |
|||
function EtymologyLanguage:makeWikipediaLink() |
|||
return "[[w:" .. self:getWikipediaArticle() .. "|" .. self:getCanonicalName() .. "]]" |
|||
end |
|||
function EtymologyLanguage:toJSON() |
|||
local ret = { |
|||
canonicalName = self:getCanonicalName(), |
|||
categoryName = self:getCategoryName(), |
|||
code = self._code, |
|||
otherNames = self:getOtherNames(true), |
|||
aliases = self:getAliases(), |
|||
varieties = self:getVarieties(), |
|||
parent = self._rawData.parent, |
|||
type = self:getType(), |
|||
} |
|||
EtymologyLanguage.__index = EtymologyLanguage |
|||
return require("Module:JSON").toJSON(ret) |
|||
local lang = {_code = code} |
|||
-- Parent is full language. |
|||
if not EtymologyLanguage._stack then |
|||
-- Create stack, accessed with rawData metamethod. |
|||
lang._stack = {EtymologyLanguage._rawData, data} |
|||
lang._rawData = setmetatable({}, { |
|||
__index = function(t, k) |
|||
-- Data that isn't inherited from the parent. |
|||
local noInherit = {aliases = true, varieties = true, otherNames = true, main_code = true} |
|||
if noInherit[k] then |
|||
return lang._stack[#lang._stack][k] |
|||
end |
|||
-- Data that is appended by each generation. |
|||
local append = {type = true} |
|||
if append[k] then |
|||
local parts = {} |
|||
for i = 1, #lang._stack do |
|||
table.insert(parts, lang._stack[i][k]) |
|||
end |
|||
if type(parts[1]) == "string" then |
|||
return table.concat(parts, ", ") |
|||
end |
|||
-- Otherwise, iterate down the stack, looking for a match. |
|||
else |
|||
local i = #lang._stack |
|||
while not lang._stack[i][k] and i > 1 do |
|||
i = i - 1 |
|||
end |
|||
return lang._stack[i][k] |
|||
end |
|||
end, |
|||
-- Retain immutability (as writing to rawData will break functionality). |
|||
__newindex = function() |
|||
error("table from mw.loadData is read-only") |
|||
end |
|||
}) |
|||
-- Non-etymological code is the parent code. |
|||
lang._nonEtymologicalCode = EtymologyLanguage._code |
|||
-- Parent is etymology language. |
|||
else |
|||
-- Copy over rawData and stack to the new object, and add new layer to stack. |
|||
lang._rawData = EtymologyLanguage._rawData |
|||
lang._stack = EtymologyLanguage._stack |
|||
table.insert(lang._stack, data) |
|||
-- Copy non-etymological code. |
|||
lang._nonEtymologicalCode = EtymologyLanguage._nonEtymologicalCode |
|||
end |
|||
lang._familyCode = familyCode |
|||
return setmetatable(lang, EtymologyLanguage) |
|||
end |
end |
||
function EtymologyLanguage:getRawData() |
|||
return self._rawData |
|||
end |
|||
EtymologyLanguage.__index = EtymologyLanguage |
|||
function export.makeObject(code, data) |
|||
return data and setmetatable({ _rawData = data, _code = code }, EtymologyLanguage) or nil |
|||
end |
|||
function export.getByCode(code) |
function export.getByCode(code) |
||
return export.makeObject(code |
return export.makeObject(code) |
||
end |
end |
||
function export.getByCanonicalName(name) |
function export.getByCanonicalName(name) |
||
local |
local byName = mw.loadData("Module:etymology languages/canonical names") |
||
local code = byName and byName[name] or |
|||
byName[name:gsub(" [Ss]ubstrate$", "")] or |
|||
byName[name:gsub("^a ", "")] or |
|||
byName[name:gsub("^a ", ""):gsub(" [Ss]ubstrate$", "")] |
|||
if not code then |
if not code then |
||
Rêza 128: | Rêza 98: | ||
end |
end |
||
return export.makeObject(code |
return export.makeObject(code) |
||
end |
end |
||
return export |
return export |
Çımraviyarnayışê 21:19, 24 Sıbate 2024
Seba na module şıma şenê yû pela dokumani vırazê Modul:etymology languages/dok
local export = {}
function export.makeObject(code)
local data = mw.loadData("Module:etymology languages/data")[code]
code = data and data.main_code or code
if not data then
return nil
end
local EtymologyLanguage = require("Module:languages").getByCode(data[5], nil, true, true)
local familyCode
if EtymologyLanguage:hasType("family") then
-- Substrates are treated as child languages of "undetermined".
if EtymologyLanguage:getCode() == "qfa-sub" then
EtymologyLanguage = require("Module:languages").getByCode("und")
end
-- True etymology-only families (e.g. "ira-old") still need to grab the family code.
familyCode = data[5]
end
-- Delete cached _type table to prevent the new object's hasType method from finding it via the metatable, as it only includes the parent's types.
EtymologyLanguage._type = nil
if not EtymologyLanguage then
return nil
end
EtymologyLanguage.__index = EtymologyLanguage
local lang = {_code = code}
-- Parent is full language.
if not EtymologyLanguage._stack then
-- Create stack, accessed with rawData metamethod.
lang._stack = {EtymologyLanguage._rawData, data}
lang._rawData = setmetatable({}, {
__index = function(t, k)
-- Data that isn't inherited from the parent.
local noInherit = {aliases = true, varieties = true, otherNames = true, main_code = true}
if noInherit[k] then
return lang._stack[#lang._stack][k]
end
-- Data that is appended by each generation.
local append = {type = true}
if append[k] then
local parts = {}
for i = 1, #lang._stack do
table.insert(parts, lang._stack[i][k])
end
if type(parts[1]) == "string" then
return table.concat(parts, ", ")
end
-- Otherwise, iterate down the stack, looking for a match.
else
local i = #lang._stack
while not lang._stack[i][k] and i > 1 do
i = i - 1
end
return lang._stack[i][k]
end
end,
-- Retain immutability (as writing to rawData will break functionality).
__newindex = function()
error("table from mw.loadData is read-only")
end
})
-- Non-etymological code is the parent code.
lang._nonEtymologicalCode = EtymologyLanguage._code
-- Parent is etymology language.
else
-- Copy over rawData and stack to the new object, and add new layer to stack.
lang._rawData = EtymologyLanguage._rawData
lang._stack = EtymologyLanguage._stack
table.insert(lang._stack, data)
-- Copy non-etymological code.
lang._nonEtymologicalCode = EtymologyLanguage._nonEtymologicalCode
end
lang._familyCode = familyCode
return setmetatable(lang, EtymologyLanguage)
end
function export.getByCode(code)
return export.makeObject(code)
end
function export.getByCanonicalName(name)
local byName = mw.loadData("Module:etymology languages/canonical names")
local code = byName and byName[name] or
byName[name:gsub(" [Ss]ubstrate$", "")] or
byName[name:gsub("^a ", "")] or
byName[name:gsub("^a ", ""):gsub(" [Ss]ubstrate$", "")]
if not code then
return nil
end
return export.makeObject(code)
end
return export