Mòideal:Language/name
(deasbaireachd⧼tpt-languages-separator⧽ ⧼tpt-languages-separator⧽eachdraidh⧼tpt-languages-separator⧽ceanglaichean⧼tpt-languages-separator⧽doc⧼tpt-languages-separator⧽bogsa-gainmhich⧼tpt-languages-separator⧽cùisean deuchainn)
This module is currently protected from editing. See the protection policy and protection log for more details. Please discuss any changes on the talk page; you may submit an edit request to ask an administrator to make an edit if it is uncontroversial or supported by consensus. You may also request that this page be unprotected. |
This module is subject to page protection. It is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing. |
This template is used on a very large number of pages. To avoid large-scale disruption and unnecessary server load, any changes to this template should first be tested in its /sandbox or /testcases subpages, or in your own user space. The tested changes can then be added to this page in one single edit. Please consider discussing any changes on the talk page before implementing them. |
This module is rated as alpha. It is ready for third-party input, and may be used on a few pages to see if problems arise, but should be watched. Suggestions for new features or changes in their input and output mechanisms are welcome. |
Uses Lua: |
This module converts ISO 639 codes and language tags into their equivalent language names (descriptions). It has three modes: simple (strict), fuzzy and formal. In simple, the whole tag needs to be an exact match; in fuzzy, only the base ISO 639 code needs to be an exact match. For example, if there's no mn-Cyrl
tag in the list, but there's mn
, simple will not be able to find a match, whereas fuzzy will. Finally, in formal, the script will attempt to properly decode the tag by language, script (writing system) and region and print its name in full. Here's how the three modes will handle zh
and zh-Hans-CN
:
{{#invoke:Language/name|simple|code=zh}} |
→ | Chinese |
{{#invoke:Language/name|simple|code=zh-Hans-CN}} |
→ | |
{{#invoke:Language/name|fuzzy|code=zh-Hans-CN}} |
→ | Chinese |
{{#invoke:Language/name|formal|code=zh-Hans-CN}} |
→ | Chinese (Han (Simplified variant), China) |
{{ISO 639 name}} and Mòideal:Language/text use fuzzy. Input is case-insensitive. If input is omitted, this module with return an error; if no match is found, it'll return an empty string that can be used with #if
constructs in wikicode, e.g. {{#if:{{ISO 639 name|{{{1}}}}}| ... }}
.
Data is pulled from /data.
For info on language tags, see BCP 47, the IANA Language Subtag Registry, Richard Ishida's Language Subtag Lookup and the IETF language tag article here on Wikipedia.
Faic cuideachd - Also see
local getArgs = require("Module:Arguments").getArgs
local p, e = {}, {}
local function __compile(...)
local r,i = "",0
for _, v in ipairs(arg) do
i = i + 1
if i == 1 then
r = v[1]
elseif i == 2 then
r = r .. " (" .. v[1]
else
r = r .. ", " .. v[1]
end
end
if i > 1 then
r = r .. ")"
end
return r
end
function e.simple(args, data)
return __compile(data.lang[args.code])
end
function e.fuzzy(args, data)
-- split lang code at '-', starting from the end, one dash at a time
-- and try to find a match; break from loop when we do
repeat
if data.lang[args.code] then
break
end
args.code = args.code:gsub("-[^-]*$", "")
until not args.code:match("-")
return __compile(data.lang[args.code])
end
function e.formal(args, data)
-- split the whole lang code up at every '-' and stick the bits in an array
local bits = {}; for match in args.code:gmatch("[^-]+") do
bits[#bits+1] = match
end
-- if length of the 2nd array item is 4, assume it's a script code,
-- otherwise a region code
if bits[2] and #bits[2] == 4 then
return __compile(data.lang[bits[1]],
data.script[bits[2]],
data.region[bits[3]]
)
else
return __compile(data.lang[bits[1]],
data.region[bits[2]]
)
end
end
for function_name in pairs(e) do
p[function_name] = function (frame)
local args = getArgs(frame)
local data = mw.loadData("Module:Language/name/data")
args.code = args.code:lower()
-- if dataset=iana, discard wp language table
if args.dataset == "iana" then
data.lang = data.lang_iana
end
return e[function_name](args, data)
end
end
return p