Jump to content

Module:MyTranslationModule/sandbox

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Gommeh (talk | contribs) at 15:26, 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:getParent().args  -- use getParent() to get args from the template
    local lang1 = args[1]
    local lang2 = args[2]

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

    local output = {}
    table.insert(output, '{| class="wikitable"')
    table.insert(output, string.format("! %s !! %s", lang1, lang2))

    for i = 3, 1000, 2 do  -- go far enough to handle lots of pairs
        local text = args[i]
        local translation = args[i + 1]
        if text and translation then
            table.insert(output, string.format("|-\n| %s || %s", text, translation))
        elseif text or translation then
            -- Uneven pair? Show as is
            table.insert(output, string.format("|-\n| %s || %s", text or "", translation or ""))
        else
            break
        end
    end

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

return p