Module:ForeignLanguageTextTable
Appearance
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'] or 'unknown'
local lang2 = args['lang2'] or 'unknown'
-- 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