Module:LangInfo
Ir a la navegación
Ir a la búsqueda
La documentación para este módulo puede ser creada en Module:LangInfo/doc
local data = mw.loadData('Module:LangInfo/data') -- manually set Wikipedia link to a language's local "<lang> language" article; in case that differs from the language's endonym local wplinks = { -- format: ["language code"] = "local Wikipedia article", ["bg"] = "Български език", ["zh"] = "汉语", ["da"] = "Dansk (sprog)", ["fi"] = "Suomen kieli", ["de"] = "Deutsche Sprache", ["hu"] = "Magyar nyelv", ["it"] = "Lingua italiana", ["hi"] = "हिन्दी", ["lv"] = "Latviešu valoda", ["lt"] = "Lietuvių kalba", ["pl"] = "Język polski", ["pt"] = "Língua portuguesa", ["ru"] = "Русский язык", ["sk"] = "Slovenčina", ["es"] = "Idioma español", ["th"] = "ภาษาไทย", ["uk"] = "Українська мова", } -- manually set country codes for countries whose official language's ISO 639-1 code is not equal to the country's ISO 3166-1 code local countrycodes = { -- format: ["language code"] = "country code", ["ar"] = "eg", ["cs"] = "cz", ["da"] = "dk", ["el"] = "gr", ["en"] = "us", ["hi"] = "in", ["ja"] = "jp", ["ko"] = "kr", ["sv"] = "se", ["uk"] = "ua", ["vi"] = "vn", ["yue"] = "cn", ["zh"] = "cn", ["es-formal"] = "es", } local trim = mw.text.trim local args_table local getArg = function(key) local value = args_table[key] if not value then return nil end value = trim(value) if value == '' then return nil end return value end ----------------------------------------------------------------- -- main return object return { go = function(frame, args) -- init cache args_table = args or frame.args local _arg1 = getArg(1) or '' local _arg2 = getArg(2) or '' if not data[_arg1] then return end if _arg2 == 'name' then if data[_arg1]['shortname'] ~= '' then return data[_arg1]['shortname'] else return data[_arg1]['fullname'] end elseif _arg2 == 'countrycode' then if countrycodes[_arg1] ~= nil then return countrycodes[_arg1] else return _arg1 end elseif _arg2 == 'wplink' and wplinks[_arg1] ~= nil then return wplinks[_arg1] elseif _arg2 == 'lname' or _arg2 == 'wplink' then return ( string.gsub(data[_arg1]['lname'], "(.-),.+", "%1") ) --only get first part of a comma-separated list elseif data[_arg1][_arg2] ~= '' then return data[_arg1][_arg2] else return '' end end }