Module:ForeignLanguageTextTable
Appearance
local p = {}
function p.generateTable(frame)
-- Get parameters from the template call
local args = frame:getParent().args
-- Base of the table
local tableStart = '{| class="wikitable"\n|+\n'
local tableHeader = '!{{ISO 639 name|' .. args.lang1 .. '}}\n!{{ISO 639 name|' .. args.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|' .. args.lang1 .. '|' .. text .. '|label=none}}\n'
tableBody = tableBody .. '|{{Langx|' .. args.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