Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Lyrics

From Sekaipedia
Revision as of 03:12, 24 June 2021 by ChaoticShadow (talk | contribs) (created lyrics module)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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
Cookies help us deliver our services. By using our services, you agree to our use of cookies.