Jump to content

Module:TableTranslation

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Gommeh (talk | contribs) at 15:21, 11 May 2025. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

local p = {}

function p.render(frame)
    local args = frame.args
    local lang1 = args[1]
    local lang2 = args[2]

    if not lang1 or not lang2 then
        return "Error: Two language names must be provided."
    end

    -- Start building the wikitext for the table
    local output = {}
    table.insert(output, '{| class="wikitable"')
    table.insert(output, string.format("! %s !! %s", lang1, lang2))

    -- Each pair: args[3] is text, args[4] is translation, etc.
    for i = 3, #args, 2 do
        local text = args[i]
        local translation = args[i + 1]
        if text and translation then
            table.insert(output, string.format("|-\n| %s || %s", text, translation))
        end
    end

    table.insert(output, "|}")

    return table.concat(output, "\n")
end

return p