Modul:wikimedia languages
Die Dokumentation für dieses Modul kann unter Modul:wikimedia languages/Doku erstellt werden
local export = {}
local WikimediaLanguage = {}
function WikimediaLanguage:getCode()
return self._code
end
function WikimediaLanguage:getCanonicalName()
return self._rawData.names[1]
end
function WikimediaLanguage:getAllNames()
return self._rawData.names
end
function WikimediaLanguage:getType()
return "Wikimedia"
end
function WikimediaLanguage:getWiktionaryLanguage()
if not self._wiktionaryLanguageObject then
self._wiktionaryLanguageObject = require("Module:languages").getByCode(self._rawData.wiktionary_code)
end
return self._wiktionaryLanguageObject
end
-- Do NOT use this method!
-- All uses should be pre-approved on the talk page!
function WikimediaLanguage:getRawData()
return self._rawData
end
WikimediaLanguage.__index = WikimediaLanguage
function export.getByCode(code)
-- Only accept codes the software recognises
if not mw.language.isKnownLanguageTag(code) then
return nil
end
local rawData = mw.loadData("Module:wikimedia languages/data")[code]
if not rawData then
-- If there is no specific Wikimedia code, then "borrow" the information
-- from the general Wiktionary language code
local lang = require("Module:languages").getByCode(code)
if not lang then
return nil
end
rawData = {names = lang:getRawData().names, wiktionary_code = code}
end
if not rawData.names then
rawData = {names = require("Module:languages").getByCode(rawData.wiktionary_code):getRawData().names, wiktionary_code = rawData.wiktionary_code}
end
return setmetatable({ _rawData = rawData, _code = code }, WikimediaLanguage)
end
function export.getByCodeWithFallback(code)
local object = export.getByCode(code)
if object then
return object
end
local lang = require("Module:languages").getByCode(code)
if not lang then
return nil
end
return lang:getWikimediaLanguages()[1]
end
return export