Jump to content

Module:ForeignLanguageTextTable: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
No edit summary
No edit summary
Line 6: Line 6:


-- Handle args explicitly to ensure parameters are properly retrieved
-- Handle args explicitly to ensure parameters are properly retrieved
local lang1 = args['lang1'] or 'unknown'
local lang1 = args['lang1']
local lang2 = args['lang2'] or 'unknown'
local lang2 = args['lang2']


-- Base of the table
-- Base of the table

Revision as of 17:43, 17 October 2024

local p = {}

function p.generateTable(frame)
    -- Get parameters from the template call
    local args = frame:getParent().args

    -- Handle args explicitly to ensure parameters are properly retrieved
    local lang1 = args['lang1']
    local lang2 = args['lang2']

    -- Base of the table
    local tableStart = '{| class="wikitable"\n|+\n'
    local tableHeader = '!{{ISO 639 name|' .. lang1 .. '}}\n!{{ISO 639 name|' .. lang2 .. '}}\n|-\n'
    local tableBody = ''

    -- Function to add a row for text and translation
    local function addRow(text, translation)
        if text and translation and text ~= '' and translation ~= '' then
            tableBody = tableBody .. '|{{Langx|' .. lang1 .. '|' .. text .. '|label=none}}\n'
            tableBody = tableBody .. '|{{Langx|' .. lang2 .. '|' .. translation .. '|label=none|italic=' .. (args.useitalic or 'no') .. '}}\n|-\n'
        end
    end

    -- Add the first two rows (mandatory ones)
    addRow(args['text1'], args['translation1'])
    addRow(args['text2'], args['translation2'])

    -- Check optional text/translation fields dynamically (text3, text4, etc.)
    for i = 3, 10 do  -- Adjust the loop limit based on how many pairs you want to support
        local text = args['text' .. i]
        local translation = args['translation' .. i]
        addRow(text, translation)
    end

    -- Combine the table parts
    local tableEnd = '|}\n'
    return tableStart .. tableHeader .. tableBody .. tableEnd
end

return p