Jump to content
Toggle menu
  • 8 articles
  • 75 files
  • 7 users
  • 37.8K edits
Neodyland Wiki
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Languages/List: Difference between revisions

From Neodyland Wiki
fix for current bug in Scribunto (table.sort currently returns an unexpeceted error and does not accept a comparison function) will be solved soon; for now keep results unsorted if there's an error
mNo edit summary
 
Line 38: Line 38:
             i = i + 1
             i = i + 1
         end
         end
         if #(p.list) ~= i then return false, ': invalid sequence: length = '.. #(p.list) ' for ' .. i .. 'distinct keys' end
         if #(p.list) ~= i then return false, ': invalid sequence: length = '.. #(p.list) ' for ' .. i .. ' distinct keys' end
         return true
         return true
     end
     end

Latest revision as of 20:34, 13 September 2023

Module documentation[ view · edit · history · purge ]
This documentation is transcluded from Module:Languages/List/doc.

Previously this module generated a static list like this:

p.list = {'qqq', 'aig', 'sma', 'ace', 'abr', 'ang', 'af', 'gsw', 'als', 'ase', 'smn', 'an', 'rup', 'aae', 'roa-rup', 'frp', 'ast', 'atj', 'gn', 'ay', 'az', 'abs', 'gor', 'id', 'ms', 'bdr', 'bm', 'zh-min-nan', 'nan-latn-pehoeji', 'nan-latn-tailo', 'bjn', 'ban', 'map-bms', 'mui', 'bug', 'btm', 'bbc', 'bbc-latn', 'bew', 'sje', 'bcl', 'bi', 'bol', 'bar', 'bs', 'brh', 'br', 'en-gb', 'ca', 'en-ca', 'cps', 'ceb', 'cs', 'cho', 'ch', 'cbk-zam', 'ny', 'chn', 'sn', 'tum', 'lua', 'sei', 'co', 'cy', 'dga', 'dag', 'da', 'se', 'se-no', 'se-se', 'se-fi', 'pdc', 'de', 'de-formal', 'nv', 'dsb', 'na', 'dua', 'mh', 'et', 'efi', 'vmw', 'egl', 'eml', 'en', 'es', 'es-formal', 'es-419', 'eo', 'ext', 'eu', 'ee', 'wls', 'gur', 'hif', 'fon', 'hif-latn', 'fo', 'fr', 'frc', 'fy', 'ff', 'gaa', 'fur', 'ga', 'gv', 'sm', 'gag', 'gd', 'gl', 'ki', 'aln', 'gpe', 'gom-latn', 'guw', 'hak-latn', 'ha', 'haw', 'ho', 'hoc-latn', 'hsb', 'hr', 'hrx', 'ibb', 'io', 'igl', 'ig', 'rw', 'rn', 'ilo', 'hil', 'ia', 'ie', 'ike-latn', 'ik', 'bto', 'nr', 'xh', 'zu', 'is', 'it', 'iba', 'jv', 'kaj', 'jut', 'kbp', 'kea', 'dtp', 'kl', 'kr', 'pam', 'krl', 'kai', 'csb', 'kw', 'hke', 'krj', 'kiu', 'sw', 'kg', 'avk', 'ses', 'ht', 'gcf', 'kri', 'gcr', 'ku', 'kge', 'ku-latn', 'kus', 'kj', 'acf', 'jbo', 'lld', 'lad', 'lkt', 'ljp', 'ltg', 'la', 'lv', 'lzz', 'to', 'lb', 'nia', 'lt', 'lij', 'li', 'ln', 'lfn', 'liv', 'olo', 'lmo', 'lg', 'yua', 'mad', 'hu', 'hu-formal', 'vmf', 'mg', 'mt', 'mnc', 'mnc-latn', 'mi', 'arn', 'mrh', 'fit', 'isv', 'isv-latn', 'fat', 'min', 'cdo-latn', 'mwl', 'lus', 'mos', 'mus', 'fj', 'nah', 'pcm', 'nap', 'ppl', 'nmz', 'nl', 'nl-informal', 'nds-nl', 'cr', 'yrl', 'niu', 'frr', 'pih', 'nb', 'no', 'nn', 'nrm', 'nov', 'sms', 'nup', 'nys', 'uz-latn', 'uz', 'ann', 'oc', 'ojb', 'frs', 'om', 'nyo', 'ttj', 'ng', 'de-at', 'hz', 'pfl', 'pag', 'ami', 'pap-aw', 'pap', 'jam', 'pcd', 'pms', 'pwn', 'nds', 'pdt', 'cpx-latn', 'pl', 'fvr', 'pt', 'pt-br', 'prg', 'kk-latn', 'aa', 'kaa', 'kk-tr', 'crh', 'crh-latn', 'ty', 'ksh', 'ro', 'rmc', 'rmy', 'rgn', 'rm', 'qug', 'qu', 'nyn', 'xsy', 'szy', 'sg', 'sc', 'sro', 'sas', 'sdc', 'sli', 'de-ch', 'sco', 'trv', 'stq', 'st', 'nso', 'tn', 'sq', 'scn', 'loz', 'simple', 'ss', 'sk', 'sl', 'szl', 'so', 'srn', 'sr-el', 'sh-latn', 'sh', 'su', 'fi', 'sv', 'shy', 'shy-latn', 'shi', 'shi-latn', 'tl', 'zgh-latn', 'kab', 'roa-tara', 'rif', 'tt-latn', 'crh-ro', 'tay', 'tet', 'din', 'vi', 'tg-latn', 'tpi', 'tok', 'chy', 'tly', 've', 'aeb-latn', 'tr', 'tk', 'tru', 'tw', 'kcg', 'ug-latn', 'vot', 'za', 'vec', 'vep', 'ruq-latn', 'ruq', 'vo', 'vro', 'fiu-vro', 'wa', 'wlx', 'bci', 'guc', 'vls', 'war', 'wal', 'wo', 'ts', 'knc', 'yo', 'diq', 'zea', 'sgs', 'bat-smg', 'grc', 'el', 'pnt', 'cop', 'av', 'ady', 'ady-cyrl', 'kbd', 'ba', 'kbd-cyrl', 'alt', 'ab', 'be', 'be-tarask', 'be-x-old', 'bg', 'bxr', 'ruq-cyrl', 'inh', 'dlg', 'os', 'sjd', 'kv', 'krc', 'kum', 'crh-cyrl', 'ky', 'mrj', 'kk', 'kk-cyrl', 'kk-kz', 'lbe', 'lez', 'mk', 'mdf', 'isv-cyrl', 'mo', 'mn', 'rut', 'gld', 'nog', 'ce', 'koi', 'mhr', 'rue', 'rsk', 'ru', 'sah', 'sty', 'cu', 'sr-ec', 'sr', 'sh-cyrl', 'tt-cyrl', 'tt', 'tly-cyrl', 'tg-cyrl', 'tg', 'tyv', 'udm', 'uz-cyrl', 'uk', 'kjh', 'xal', 'cv', 'myv', 'xmf', 'ka', 'hyw', 'hy', 'anp', 'awa', 'ks-deva', 'gom-deva', 'gom', 'dty', 'new', 'pi', 'ne', 'bho', 'bh', 'mag', 'mr', 'mai', 'sa', 'bgc', 'hi', 'as', 'bn', 'bpy', 'pa', 'gu', 'or', 'ta', 'nit', 'te', 'kn', 'tcy', 'ml', 'si', 'syl', 'dz', 'mni', 'bo', 'bug-bugi', 'ksw', 'blk', 'shn', 'kjp', 'mnw', 'my', 'rki', 'ccp', 'km', 'th', 'tdd', 'nod', 'lo', 'ban-bali', 'jv-java', 'sat', 'chr', 'ike-cans', 'iu', 'tzm', 'got', 'zgh', 'shi-tfng', 'tig', 'ti', 'am', 'ii', 'ko-kp', 'ko', 'ja', 'ryu', 'zh', 'zh-mo', 'zh-cn', 'zh-sg', 'zh-hans', 'zh-hant', 'zh-tw', 'zh-hk', 'zh-my', 'wuu-hant', 'wuu', 'wuu-hans', 'hak', 'hak-hant', 'hak-hans', 'lzh', 'zh-classical', 'hsn', 'yue', 'zh-yue', 'yue-hant', 'yue-hans', 'cpx', 'cpx-hant', 'cpx-hans', 'gan', 'gan-hant', 'gan-hans', 'nan', 'nan-hant', 'cdo', 'cdo-hant', 'mnc-mong', 'yi', 'he', 'ug-arab', 'ug', 'ur', 'ary', 'ar', 'bqi', 'ms-arab', 'ps', 'pnb', 'aeb-arab', 'aeb', 'azb', 'arq', 'bcc', 'bgn', 'skr', 'skr-arab', 'sd', 'acm', 'apc', 'fa', 'kk-arab', 'kk-cn', 'ku-arab', 'ks', 'ks-arab', 'khw', 'ckb', 'sdh', 'glk', 'lrc', 'luz', 'lki', 'arz', 'mzn', 'hno', 'arc', 'dv', 'nqo'}

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.

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;
Cookies help us deliver our services. By using our services, you agree to our use of cookies.