Module:MyTranslationModule/sandbox
Appearance
![]() | This is the module sandbox page for Module:MyTranslationModule (diff). |
local p = {}
function p.render(frame)
local args = frame:getParent().args
-- Support lang1/lang2 or positional args 1/2
local lang1 = args["lang1"] or args[1]
local lang2 = args["lang2"] or args[2]
if not lang1 or not lang2 then
return "Error: You must specify two language names."
end
local output = {}
table.insert(output, '{| class="wikitable"')
table.insert(output, string.format("! %s !! %s", lang1, lang2))
-- First, process named args like text1/trans1, text2/trans2
local i = 1
while true do
local text = args["text" .. i]
local trans = args["trans" .. i]
if not text and not trans then break end
table.insert(output, string.format("|-\n| %s || %s", text or "", trans or ""))
i = i + 1
end
-- Then add any *remaining* unnamed args starting from 3 onward
for j = 3, #args, 2 do
local text = args[j]
local trans = args[j + 1]
if text or trans then
table.insert(output, string.format("|-\n| %s || %s", text or "", trans or ""))
end
end
table.insert(output, "|}")
return table.concat(output, "\n")
end
return p