Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Other Languages: Difference between revisions

From 1F616EMO Survival Server Wiki
No edit summary
No edit summary
Line 51: Line 51:
             if stickTl and (lang == "sr-Latn" or lang == "zh-TW") then
             if stickTl and (lang == "sr-Latn" or lang == "zh-TW") then
                 tbRows[#tbRows].tl_colspan = 2
                 tbRows[#tbRows].tl_colspan = 2
                row.tl_skip = true
                 stickTl = false
                 stickTl = false
             elseif lang == "sr-Cyrl" or lang == "sr-Latn" then
             elseif lang == "sr-Cyrl" or lang == "sr-Latn" then
Line 91: Line 92:
             text:wikitext('<br />'):tag('small'):tag('i'):wikitext(row.rm)
             text:wikitext('<br />'):tag('small'):tag('i'):wikitext(row.rm)
         end
         end
         if haveTl then
         if haveTl and not row.tl_skip then
             local tl = tr:tag('td'):wikitext(row.tl or "—"):attr('colspan', tostring(row.tl_colspan))
             local tl = tr:tag('td'):wikitext(row.tl or "—"):attr('colspan', tostring(row.tl_colspan))
             if row.note then
             if row.note then

Revision as of 14:07, 9 July 2024

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
                row.tl_skip = true
                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 and not row.tl_skip 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 tostring(tb) .. frame:extensionTag { name = 'references', args = { group = '•' } }
end

return p