モジュール:Languages/List

< モジュール:Languages
2015年6月19日 (金) 08:35時点におけるWikiSysop (トーク | 投稿記録)による版 (1版)
(差分) ← 古い版 | 最新版 (差分) | 新しい版 → (差分)

このモジュールについての説明文ページを モジュール:Languages/List/doc に作成できます

local p = {};

--[[
// JavaScript-snippet to update this list:
var list = "";
$.each(wpAvailableLanguages, function(lang, _) {
    list += "'" + lang + "',";
})
console.log("p.list={" + list + "}")
]]

-- @Deprecated
-- p.list={'aa','ab','ace','aeb','af','ak','aln','als','am','an','ang','anp','ar','arc','arn','arq','ary','arz','as','ast','av','avk','ay','az','azb','ba','bar','bat-smg','bbc','bbc-latn','bcc','bcl','be','be-tarask','be-x-old','bg','bgn','bh','bho','bi','bjn','bm','bn','bo','bpy','bqi','br','brh','bs','bto','bug','bxr','ca','cbk-zam','cdo','ce','ceb','ch','cho','chr','chy','ckb','co','cps','cr','crh','crh-cyrl','crh-latn','cs','csb','cu','cv','cy','da','de','de-at','de-ch','de-formal','diq','dsb','dtp','dv','dz','ee','egl','el','eml','en','en-ca','en-gb','eo','es','et','eu','ext','fa','ff','fi','fit','fiu-vro','fj','fo','fr','frc','frp','frr','fur','fy','ga','gag','gan','gan-hans','gan-hant','gd','gl','glk','gn','gom-latn','got','grc','gsw','gu','gv','ha','hak','haw','he','hi','hif','hif-latn','hil','ho','hr','hrx','hsb','ht','hu','hy','hz','ia','id','ie','ig','ii','ik','ike-cans','ike-latn','ilo','inh','io','is','it','iu','ja','jam','jbo','jut','jv','ka','kaa','kab','kbd','kbd-cyrl','kg','khw','ki','kiu','kj','kk','kk-arab','kk-cn','kk-cyrl','kk-kz','kk-latn','kk-tr','kl','km','kn','ko','koi','ko-kp','kr','krc','kri','krj','ks','ks-arab','ks-deva','ksh','ku','ku-arab','ku-latn','kv','kw','ky','la','lad','lb','lbe','lez','lfn','lg','li','lij','liv','lmo','ln','lo','loz','lrc','lt','ltg','lus','lv','lzh','lzz','mai','map-bms','mdf','mg','mh','mhr','mi','min','mk','ml','mn','mo','mr','mrj','ms','mt','mus','mwl','my','myv','mzn','na','nah','nan','nap','nb','nds','nds-nl','ne','new','ng','niu','nl','nl-informal','nn','no','nov','nrm','nso','nv','ny','oc','om','or','os','pa','pag','pam','pap','pcd','pdc','pdt','pfl','pi','pih','pl','pms','pnb','pnt','prg','ps','pt','pt-br','qu','qug','rgn','rif','rm','rmy','rn','ro','roa-rup','roa-tara','ru','rue','rup','ruq','ruq-cyrl','ruq-latn','rw','sa','sah','sat','sc','scn','sco','sd','sdc','se','sei','ses','sg','sgs','sh','shi','shi-latn','shi-tfng','si','simple','sk','sl','sli','sm','sma','sn','so','sq','sr','sr-ec','sr-el','srn','ss','st','stq','su','sv','sw','szl','ta','tcy','te','tet','tg','tg-cyrl','tg-latn','th','ti','tk','tl','tly','tn','to','tokipona','tpi','tr','tru','ts','tt','tt-cyrl','tt-latn','tum','tw','ty','tyv','tzm','udm','ug','ug-arab','ug-latn','uk','ur','uz','uz-cyrl','uz-latn','ve','vec','vep','vi','vls','vmf','vo','vot','vro','wa','war','wo','wuu','xal','xh','xmf','yi','yo','yue','za','zea','zh','zh-classical','zh-cn','zh-hans','zh-hant','zh-hk','zh-min-nan','zh-mo','zh-my','zh-sg','zh-tw','zh-yue','zu',}

--
--[[ 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
    table.sort(sortedList)
    return sortedList
end

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;