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
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))
-- Named text/trans pairs
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
-- Positional parameters (start from 3rd parameter onward)
local index = 3
while true do
local text = args[index]
local trans = args[index + 1]
if not text and not trans then break end
table.insert(output, string.format("|-\n| %s || %s", text or "", trans or ""))
index = index + 2
end
table.insert(output, "|}")
return table.concat(output, "\n")
end
return p