Module:Languages/List
CodeDiscussionEditHistoryLinksLink count Subpages:DocumentationTestsResultsSandboxLive code All modules
Previously this module generated a static list like this:
p.list = {'hak-hant', 'als', 'id', 'bdr', 'ase', 'sma', 'smn', 'gn', 'frp', 'nr', 'knc', 'nan-latn-pehoeji', 'isv-cyrl', 'hak-latn', 'bjn', 'ast', 'zh-min-nan', 'lua', 'ang', 'ms', 'en-us', 'abs', 'kge', 'bas', 'hak-hans', 'az', 'gor', 'af', 'ace', 'bkh', 'agq', 'atj', 'bkc', 'ay', 'bfd', 'mui', 'isv-latn', 'map-bms', 'tig', 'ccp', 'bax', 'gsw', 'acf', 'nan-latn-tailo', 'ak', 'bgc', 'iba', 'hke', 'rup', 'bm', 'roa-rup', 'aae', 'ban', 'ksf', 'bug', 'nup', 'an', 'btm', 'ibb', 'en-gb', 'jbo', 'ny', 'se-no', 'br', 'pcm', 'mi', 'isu', 'min', 'etu', 'bbc', 'aln', 'ilo', 'eu', 'lv', 'rmf', 'kai', 'bew', 'pam', 'fat', 'nys', 'lld', 'guw', 'hil', 'gom-latn', 'gv', 'lad', 'bbc-latn', 'cnh', 'gcf', 'bkm', 'nah', 'ku-latn', 'ik', 'eml', 'lij', 'kw', 'dga', 'eto', 'rw', 'bcl', 'co', 'mad', 'ku', 'se', 'se-fi', 'bar', 'mnc-latn', 'ext', 'sei', 'gaa', 'hrx', 'byv', 'ewo', 'ha', 'kj', 'ia', 'krj', 'kea', 'nap', 'niu', 'lmo', 'pdc', 'mcp', 'gag', 'mua', 'kri', 'fmp', 'avk', 'sje', 'dua', 'li', 'ki', 'frr', 'dtp', 'arn', 'ch', 'nla', 'nmz', 'wls', 'ceb', 'lem', 'sms', 'lfn', 'de-formal', 'tum', 'mh', 'it', 'srq', 'mt', 'fj', 'olo', 'ht', 'pih', 'fy', 'haw', 'lg', 'kg', 'cy', 'mg', 'sw', 'ig', 'lzz', 'ann', 'nv', 'et', 'cak', 'gcr', 'dag', 'ff', 'la', 'lns', 'na', 'kbp', 'hif', 'lus', 'mus', 'mrh', 'jut', 'zu', 'cho', 'vmw', 'liv', 'nnz', 'ee', 'de', 'cbk-zam', 'uz-latn', 'nds-nl', 'nia', 'vmf', 'bbj', 'ie', 'bi', 'uz', 'mos', 'mwl', 'chn', 'es-419', 'csb', 'nl-informal', 'xh', 'yas', 'es', 'hif-latn', 'kus', 'da', 'gd', 'bqz', 'nge', 'efi', 'egl', 'igl', 'yrl', 'is', 'dsb', 'ga', 'ca', 'gl', 'kl', 'nl', 'lt', 'ltg', 'se-se', 'gpe', 'nov', 'nb', 'lb', 'cs', 'bs', 'fr', 'hr', 'kr', 'frc', 'kiu', 'nrm', 'sm', 'cps', 'gur', 'en', 'ln', 'brh', 'jv', 'nmg', 'hu-formal', 'cr', 'ike-latn', 'nn', 'nnh', 'sn', 'rn', 'fit', 'hsb', 'en-ca', 'ho', 'eo', 'fo', 'io', 'fon', 'bto', 'ses', 'ker', 'no', 'to', 'gya', 'krl', 'fkv', 'es-formal', 'fur', 'hu', 'smj', 'oc', 'tok', 'nso', 'kk-cn', 'bo', 'roa-tara', 'pnt', 'rmc', 'so', 'ts', 'mo', 'tpi', 'vep', 'be-tarask', 'lo', 'ko', 'luz', 'wes', 'ary', 'alt', 'krc', 'anp', 'lrc', 'yi', 'shy-latn', 'arz', 'inh', 'crh-latn', 'sq', 'tn', 'mn', 'nds', 'ar', 'kn', 'crh', 'tru', 'sr', 'nqo', 'kk-tr', 'am', 'mhr', 'got', 'gom-deva', 'qug', 'kk-latn', 'rm', 'or', 'om', 'nod', 'km', 'arc', 'mr', 'mni', 'mnc', 'hsn', 'apc', 'crh-ro', 'ur', 'yo', 'vo', 'ty', 'pnb', 'new', 'sl', 'tl', 'zh-tw', 'chr', 'zh-sg', 'pl', 'ml', 'sty', 'ss', 'vot', 'zh-my', 'zh-mo', 'ps', 'os', 'el', 'ku-arab', 'ks', 'kjp', 'zh-hans', 'dty', 'war', 'zgh', 'shn', 'sh-cyrl', 'bgn', 'zea', 'yue-hans', 'sd', 'tt-latn', 'skr-arab', 'ybb', 'yue-hant', 'xsy', 'xmf', 'nan-hani', 'tzm', 'wuu-hant', 'wuu', 'tg-cyrl', 'wo', 'ru', 'zh-cn', 'te', 'ryu', 'wuu-hans', 'ne', 'ota', 'ady', 'bho', 'vi', 'vec', 've', 'be', 'ce', 'uz-cyrl', 'uk', 'ug-latn', 'ug-arab', 'dz', 'udm', 'tyv', 'nyo', 'hz', 'cpx-latn', 'mnw', 'tw', 'tvu', 'ttj', 'tt-cyrl', 'ckb', 'trv', 'rut', 'pt-br', 'vut', 'loz', 'tr', 'shi', 'th', 'sdc', 'tcy', 'my', 'yue', 'za', 'mai', 'ug', 'hak', 'sg', 'tg', 'ojb', 'de-ch', 'ng', 'bg', 'sv', 'hy', 'su', 'bpy', 'ady-cyrl', 'ksh', 'tet', 'awa', 'ko-kp', 'sh-latn', 'sro', 'szy', 'tly', 'srn', 'arq', 'sr-el', 'as', 'sh', 'pwn', 'sdh', 'sr-ec', 'bat-smg', 'vls', 'kum', 'shi-tfng', 'hno', 'bh', 'tg-latn', 'skr', 'gom', 'hyw', 'pfl', 'fi', 'simple', 'mnc-mong', 'shy', 'hi', 'si', 'ks-deva', 'ti', 'zh', 'zh-classical', 'ka', 'koi', 'lzh', 'be-x-old', 'rue', 'gan-hant', 'pa', 'myv', 'ami', 'sgs', 'gan-hans', 'syl', 'mk', 'kk', 'mdf', 'rsk', 'tk', 'pms', 'ksw', 'ban-bali', 'sk', 'ro', 'kcg', 'fiu-vro', 'szl', 'bn', 'kk-kz', 'zh-hk', 'ruq-latn', 'ruq-cyrl', 'sah', 'rgn', 'kab', 'rmy', 'zh-hant', 'pi', 'kbd', 'lez', 'rif', 'diq', 'quc', 'lbe', 'zgh-latn', 'aeb-latn', 'prg', 'kaa', 'cv', 'dv', 'ks-arab', 'sat', 'jam', 'grc', 'kk-cyrl', 'shi-latn', 'kv', 'gan', 'nan', 'sco', 'ike-cans', 'din', 'bqi', 'pdt', 'khw', 'kjh', 'pap-aw', 'pap', 'kk-arab', 'cdo', 'av', 'chy', 'aeb-arab', 'acm', 'nyn', 'kbd-cyrl', 'bxr', 'iu', 'tdd', 'gu', 'pcd', 'aeb', 'crh-cyrl', 'lki', 'azb', 'qu', 'wya', 'bcc', 'rki', 'stq', 'mag', 'pag', 'guc', 'nit', 'de-at', 'mcn', 'mzn', 'zh-yue', 'st', 'tt', 'nan-hant', 'tly-cyrl', 'tay', 'he', 'scn', 'ky', 'sjd', 'cpx-hans', 'osa-latn', 'ta', 'wa', 'ruq', 'sa', 'ms-arab', 'mrj', 'cpx', 'ja', 'ii', 'fa', 'pt', 'aa', 'ba', 'bag', 'wal', 'xal', 'yav', 'gld', 'bci', 'sli', 'glk', 'ab', 'blk', 'rwr', 'cu', 'cpx-hant', 'yat', 'sju', 'sc', 'nog', 'vro'}
Now this list is generated from the internal list of supported languages in the local instance of MediaWiki, which is then sorted by native name of each language in its primary script (LTR scripts are sorted before RTL scripts, language names in the same script are sorted together.
The order is also consistant with Module:Multilingual description which has its own comprehensive tests for the sort order of the list, its completeness (all language codes supported by the local instance of Mediawiki, plus some known aliases needed for BCP 47 conformance or for compatibility with past versions of this wiki even if they are not supported now and not shown in the list above), as well as for the directionality of each language.
Note that as of 2020-10-18, there's a new bug in Scribunto, which causes the standard "table.sort()" function to no longer accept a standard comparison function. Now when "table.sort()" fails, the error is correctly catched (instead of producing a viabile error), but the list may not be sorted correctly (temporarily) in some cases. The bug is tracked and corrected in Mediawiki but waiting to be deployed with the fix. Nothing will need to be changed (using "perror()" will then no longer have any effect, it is just needed for now and the bug was not a bug of this module which was properly tested and sudddently failed unexpectedly). Thanks.
Code
local p = {};
local nativeList = require('Module:Multilingual description/sort')
local nativeListIndex = {}
for i, lang in ipairs(nativeList) do
nativeListIndex[lang] = i
end
--
--[[ Check this list by running this in the console of the Lua Module editor in MediaWiki:
="p.list = {'" .. table.concat(p.getSortedList(mw.language.fetchLanguageNames()), "', '") .. "'}"
]]
function p.getSortedList(mwLangList)
local sortedList = {}
for lang, _ in pairs(mwLangList) do
table.insert(sortedList, lang)
end
pcall(function()
table.sort(sortedList, function(lang1, lang2)
return (nativeListIndex[lang1] or -1) <= (nativeListIndex[lang2] or -1)
end)
end)
return sortedList
end
-- note that this fetch will be costly if all these languages are loaded individually with their data by Mediawiki
p.list = p.getSortedList(mw.language.fetchLanguageNames())
setmetatable(p, {
quickTests = function()
local i = 0
for k, v in pairs(p.list) do
if type(k) ~= 'number' or k < 1 or k ~= math.floor(k)
or type(v) ~= 'string' or #v < 2 or #v > 16
or (v):find('^[a-z][%-0-9a-z]*[0-9a-z]$') ~= 1 then
return false, ': invalid sequence of language codes in p.list["' .. tostring(k) .. '"] = "' .. tostring(v) .. '"'
end
i = i + 1
end
if #(p.list) ~= i then return false, ': invalid sequence: length = '.. #(p.list) ' for ' .. i .. ' distinct keys' end
return true
end
})
--[[ To test this module in the Lua console:
=getmetatable(p).quickTests() -- must return true
--]]
return p;