Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.
Revision as of 14:04, 9 July 2024 by 1F616EMO (talk | contribs)

local langOrder = {
    -- Retrieved from CMake output, put English first
    -- Substitude all _ to -
    "en",
    "be", "bg", "ca", "cs", "cy", "da", "de", "el", "eo", "es", "et", "eu",
    "fa", "fi", "fil", "fr", "ga", "gd", "gl", "hu", "ia", "id", "it", "ja",
    "jbo", "jv", "kk", "ko", "ky", "lt", "lv", "lzh", "mi", "mn", "mr", "ms",
    "nb", "nl", "nn", "oc", "pl", "pt", "pt-BR", "ro", "ru", "sk", "sl",
    "sr-Cyrl", "sr-Latn", "sv", "sw", "tr", "tt", "uk", "vi", "yue",
    "zh-CN", "zh-TW" }
local languageData = require('Module:Language/data/ISO 639-1')
local p = {}

function p.main(frame)
    local args = require('Module:Arguments').getArgs(frame, {
        parentFirst = true,
        removeBlanks = false,
        wrappers = { 'Template:Other Languages' }
    })
    local tbRows = {}
    local stickTl = false
    local haveTl = false

    -- <lang>: In-game Name
    -- <lang_rm: Romanization
    -- <lang>_tl: Literal Meaning
    for _, lang in ipairs(langOrder) do
        if args[lang] then
            local row = {}
            row.lang = lang
            row.text = args[lang]

            if lang == "pt-BR" then
                row.name = "Brazilian Portuguese"
            elseif lang == "sr-Cyrl" then
                row.name = "Serbian (Cyrillic)"
                stickTl = true
            elseif lang == "sr-Latn" then
                row.name = "Serbian (Latin)"
            elseif lang == "zh-CN" then
                row.name = "Chinese (Simplified)"
                stickTl = true
            elseif lang == "zh-TW" then
                row.name = "Chinese (Traditional)"
            else
                row.name = languageData[lang][1]
            end

            row.rm = args[lang .. "_rm"]

            if stickTl and (lang == "sr-Latn" or lang == "zh-TW") then
                tbRows[#tbRows].tl_colspan = 2
                stickTl = false
            elseif lang == "sr-Cyrl" or lang == "sr-Latn" then
                row.tl = args.sr_tl
                row.note = args.sr_note
            elseif lang == "zh-CN" or lang == "zh-TW" then
                row.tl = args.zh_tl
                row.note = args.zh_note
            else
                row.tl = args[lang .. "_tl"]
                row.note = args[lang .. "_note"]
            end

            if row.tl then
                haveTl = true
            end

            row.tl_colspan = 1

            tbRows[#tbRows + 1] = row
        end
    end

    local tb = mw.html.create('table'):addClass('wikitable'):newline()
    local header = tb:tag('tr')
    header:tag('th'):wikitext('Language')
    header:tag('th'):wikitext('In-game Name')
    if haveTl then
        header:tag('th'):wikitext('Literal Meaning')
    end

    local haveNote = false

    for _, row in ipairs(tbRows) do
        local tr = tb:tag('tr')
        tr:tag('td'):wikitext(row.name)

        local text = tr:tag('td'):wikitext(row.text)
        if row.rm then
            text:wikitext('<br />'):tag('small'):tag('i'):wikitext(row.rm)
        end
        if haveTl then
            local tl = tr:tag('td'):wikitext(row.tl or "—"):attr('colspan', tostring(row.tl_colspan))
            if row.note then
                haveNote = true
                tl:wikitext(frame:extensionTag {
                    name = 'ref',
                    content = row.note,
                    args = { name = row.lang, group = '•' }
                })
            end
        end
    end

    return tb .. frame:extensionTag { name = 'references', args = { group = '•' } }
end

return p