Module:ForeignLanguageTextTable: Difference between revisions
Appearance
Content deleted Content added
No edit summary |
No edit summary |
||
Line 2: | Line 2: | ||
function p.generateTable(frame) |
function p.generateTable(frame) |
||
-- |
-- Input variables from the template |
||
local |
local lang1 = frame.args["lang1"] |
||
local lang2 = frame.args["lang2"] |
|||
-- Handle args explicitly to ensure parameters are properly retrieved |
|||
local |
local texts = {} |
||
local |
local translations = {} |
||
⚫ | |||
-- Base of the table |
|||
for i = 1, 10 do |
|||
⚫ | |||
⚫ | |||
local tableHeader = '!{{ISO 639 name|' .. lang1 .. '}}\n!{{ISO 639 name|' .. lang2 .. '}}\n|-\n' |
|||
local |
local trans = frame.args["trans" .. i] |
||
if text and trans then |
|||
table.insert(texts, text) |
|||
local function addRow(text, translation) |
|||
table.insert(translations, trans) |
|||
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 |
||
end |
end |
||
-- |
-- Start building the table |
||
⚫ | |||
addRow(args['text1'], args['translation1']) |
|||
tableStr = tableStr .. "! " .. lang1 .. " !! " .. lang2 .. "\n" |
|||
addRow(args['text2'], args['translation2']) |
|||
-- Loop through the texts and translations and add rows to the table |
|||
-- Check optional text/translation fields dynamically (text3, text4, etc.) |
|||
for i = 1, #texts do |
|||
for i = 3, 10 do -- Adjust the loop limit based on how many pairs you want to support |
|||
tableStr = tableStr .. "|-\n" |
|||
tableStr = tableStr .. "| " .. texts[i] .. " || " .. translations[i] .. "\n" |
|||
⚫ | |||
⚫ | |||
end |
end |
||
-- |
-- Close the table |
||
tableStr = tableStr .. "|}" |
|||
return tableStart .. tableHeader .. tableBody .. tableEnd |
|||
return tableStr |
|||
end |
end |
||
Revision as of 18:09, 17 October 2024
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