Module:LyricsBox
Jump to navigation
Jump to search
Documentation for this module may be created at Module:LyricsBox/doc
local getArgs = require('Module:Arguments').getArgs
local p = {}
local languageTable = mw.loadData("Module:Language/Subtags").languageTable
local scriptTable = mw.loadData("Module:Language/Subtags").scriptTable
function p.main(frame)
local args = getArgs(frame)
local output = ""
local mobileOutput = ""
local language = "en"
local script = ""
local direction = ""
if args["language"] then
language = args["language"]
end
if not args["language"] and args["lang"] then
language = args["lang"]
end
if language:match("%u%l%l%l") then
script = language:match("%u%l%l%l")
language = mw.ustring.gsub(language,"-"..script,"")
end
script = "Latn" --Due to line-spacing issues
if not languageTable[language] then
error('Language with code "' .. language .. '" is not defined')
end
--if script == "" and languageTable[language]["defaultScript"] then
-- script = languageTable[language]["defaultScript"]
--end
local romanizedLangCode = ""
if languageTable[language]["romanizedTag"] then
romanizedLangCode = language .. "-Latn-" .. languageTable[language]["romanizedTag"]
else
romanizedLangCode = language .. "-Latn"
end
local fullLangCode = ""
if not (script == languageTable[language]["defaultScript"] and languageTable[language]["suppressScript"]) then
fullLangCode = language .. "-" .. script
else
fullLangCode = language
end
local counter = 1
while args[counter] do
counter = counter + 1
end
local columnCount = counter - 1
--output = "!Lyrics"
function newColumn(label)
output = output .. "!!" .. label
end
local romanizationLabel = "Romanization"
if language == "en" or language == "ja" then
romanizationLabel = "Hepburn"
end
--Logic might be slightly flawed but whatever
if columnCount == 3 then
--newColumn(romanizationLabel)
--newColumn("Translation")
output = output .. '\n|-class="nomobile"\n|lang="'..fullLangCode..'"|\n\n' .. args[1] .. '\n|lang="'..romanizedLangCode..'"|\n\n' .. args[2] .. '\n|\n\n' .. args[3]
mobileOutput = mobileOutput .. '\n|-class="mobileonly"\n|lang="'..fullLangCode..'"|\n\n' .. args[1] .. '\n|-class="mobileonly"\n|lang="'..romanizedLangCode..'"|\n\n' .. args[2] .. '\n|-class="mobileonly"\n|\n\n' .. args[3]
elseif columnCount == 2 then
if script == "Latn" and language ~= "en" then
--newColumn("Translation")
output = output .. '\n|-class="nomobile"\n|lang="'..fullLangCode..'"|\n\n' .. args[1] .. '\n|\n\n' .. args[2]
mobileOutput = mobileOutput .. '\n|-class="mobileonly"\n|lang="'..fullLangCode..'"|\n\n' .. args[1] .. '\n|-class="mobileonly"\n|\n\n' .. args[2]
else
--newColumn(romanizationLabel)
output = output .. '\n|-class="nomobile"\n|lang="'..fullLangCode..'"|\n\n' .. args[1] .. '\n|lang="'..romanizedLangCode..'"|\n\n' .. args[2]
mobileOutput = mobileOutput .. '\n|-class="mobileonly"\n|lang="'..fullLangCode..'"|\n\n' .. args[1] .. '\n|-class="mobileonly"\n|lang="'..romanizedLangCode..'"|\n\n' .. args[2]
end
elseif columnCount == 1 then
output = output .. '\n|-\n|lang="'..fullLangCode..'"|\n\n' .. args[1]
else
error("Unexpected number of columns")
end
output = string.gsub(output, "\"ja\"", "\"ja-Latn\"")
output = output .. mobileOutput
return output
end
return p