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
 
(3 intermediate revisions by the same user not shown)
Line 69: Line 69:
                 row.name = "Serbian<br><small>(Latin)</small>"
                 row.name = "Serbian<br><small>(Latin)</small>"
             elseif lang == "zh-CN" then
             elseif lang == "zh-CN" then
                row.lang = "zh-Hans"
                 row.name = "Chinese<br><small>(Simplified)</small>"
                 row.name = "Chinese<br><small>(Simplified)</small>"
                 stickTl = true
                 stickTl = true
             elseif lang == "zh-TW" then
             elseif lang == "zh-TW" then
                row.lang = "zh-Hant"
                 row.name = "Chinese<br><small>(Traditional)</small>"
                 row.name = "Chinese<br><small>(Traditional)</small>"
            elseif lang == "yue" then -- ISO 693-3
                row.name = "Yue Chinese"
             else
             else
                 row.name = languageData[lang][1]
                 row.name = languageData[lang][1]
Line 97: Line 101:
                 haveTl = true
                 haveTl = true
             end
             end
            frame:extensionTag { name = 'references', args = { group = '•' } }
             row.tl_rowspan = 1
             row.tl_rowspan = 1


Line 126: Line 129:
                     name = 'ref',
                     name = 'ref',
                     content = row.note,
                     content = row.note,
                     args = { name = tbRows[1].text .. row.lang, group = '•' }
                     args = { name = prefix .. row.lang, group = '•' }
                 })
                 })
             end
             end

Latest revision as of 14:47, 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' }
    })
    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.lang = "zh-Hans"
                row.name = "Chinese<br><small>(Simplified)</small>"
                stickTl = true
            elseif lang == "zh-TW" then
                row.lang = "zh-Hant"
                row.name = "Chinese<br><small>(Traditional)</small>"
            elseif lang == "yue" then -- ISO 693-3
                row.name = "Yue Chinese"
            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