Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.
Revision as of 14:31, 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' }
    })
    return p._main(args, frame)
end

function p._main(args, frame)
    local out
    if args["1_en"] then
        out = mw.html.create('div'):css {
            ['display'] = 'flex',
            ['column-gap'] = '15px',
            ['flex-direction'] = 'row',
            ['flex-wrap'] = 'wrap'
        }
        local Y = 1
        local y = tostring(Y)
        repeat
            local entry = out:tag('div')
            entry:tag('h3'):wikitext(args[y .. '_header'] or args[y .. '_en'])
            entry:node(p.Table(args, frame, (y .. '_')))

            Y = Y + 1
            y = tostring(Y)
        until not args[y .. "_en"]
    else
        out = p.Table(args, frame, "")
    end

    return tostring(out) .. frame:extensionTag { name = 'references', args = { group = '•' } }
end

function p.Table(args, frame, prefix)
    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[prefix .. lang] then
            local row = {}
            row.lang = lang
            row.text = args[prefix .. lang]

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

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

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

            if row.tl then
                haveTl = true
            end
            row.tl_rowspan = 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

    for _, row in ipairs(tbRows) do
        local tr = tb:tag('tr')
        tr:tag('td'):tag('b'):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 and not row.tl_skip then
            local tl = tr:tag('td'):wikitext(row.tl or "—"):attr('rowspan', tostring(row.tl_rowspan))
            if row.note then
                tl:wikitext(frame:extensionTag {
                    name = 'ref',
                    content = row.note,
                    args = { name = prefix .. row.lang, group = '•' }
                })
            end
        end
    end

    return tb
end

return p