Jump to content

Module:ForeignLanguageTextTable

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Gommeh (talk | contribs) at 18:09, 17 October 2024. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
local p = {}

function p.generateTable(frame)
    -- Input variables from the template
    local lang1 = frame.args["lang1"]
    local lang2 = frame.args["lang2"]
    
    local texts = {}
    local translations = {}
    
    -- Collect up to 10 text and translation pairs
    for i = 1, 10 do
        local text = frame.args["text" .. i]
        local trans = frame.args["trans" .. i]
        
        if text and trans then
            table.insert(texts, text)
            table.insert(translations, trans)
        end
    end
    
    -- Start building the table
    local tableStr = '{| class="wikitable"\n'
    tableStr = tableStr .. "! " .. lang1 .. " !! " .. lang2 .. "\n"
    
    -- Loop through the texts and translations and add rows to the table
    for i = 1, #texts do
        tableStr = tableStr .. "|-\n"
        tableStr = tableStr .. "| " .. texts[i] .. " || " .. translations[i] .. "\n"
    end
    
    -- Close the table
    tableStr = tableStr .. "|}"
    
    return tableStr
end

return p