Documentation for this module may be created at Module:Lyrics/doc
local p = {}
function p.main(frame)
local args = frame:getParent().args
local root = mw.html.create('table'):addClass('wikitable')
languages = {
{
name = "Japanese Lyrics",
pattern = "^japanese[0-9]+$",
lyrics = {}
},
{
name = "Romaji Lyrics",
pattern = "^romaji[0-9]+$",
lyrics = {}
},
{
name = " English Translation",
pattern = "^english[0-9]+$",
lyrics = {}
}
}
for k,v in pairs(args) do
for _,lang in ipairs(languages) do
if string.match(k, lang.pattern) then
ind = tonumber(string.match(k, "[0-9]+"))
lang.lyrics[ind] = v
break
end
end
end
local maxLen = 0
for _,lang in pairs(languages) do
maxLen = math.max(maxLen, #lang.lyrics)
end
local _row = root:tag('tr')
for _,lang in ipairs(languages) do
_row:tag('th'):css('width', string.format("%d\%%", 100 / #languages)):wikitext(lang.name)
end
for i=1,maxLen,1 do
local _row = root:tag('tr')
local nextContent = nil
for _,lang in ipairs(languages) do
local content = "<br />"
if lang.lyrics[i] and lang.lyrics[i] ~= "''" and lang.lyrics[i] ~= '""' then
content = lang.lyrics[i]
end
_row:tag('td'):wikitext(content)
nextContent = lang.lyrics[i+1] or nextContent
end
if nextContent == nil then
break
end
end
return tostring(root)
end
return p