Module:Lyrics

From Moegirlpedia
Jump to: navigation, search

Documentation for this module may be created at Module:Lyrics/doc

local p = {}

local getArgs = require('Module:Arguments').getArgs
local lang = require('Module:Lang')

function p._lyrics(args)
	local orig = mw.text.split(args.original or '', '\n')
	local tran = mw.text.split(args.translated or '', '\n')
	local llang = args.llang or 'ja'
	local rlang = args.rlang or 'zh'
	local lstyle = 'width:49.85%;min-width:300px;display:inline-block;vertical-align:top;white-space:pre-wrap;' .. (args.lstyle or '')
	local rstyle = 'width:49.85%;min-width:300px;display:inline-block;vertical-align:top;white-space:pre-wrap;' .. (args.rstyle or '')

	if args.original:match('<ruby') then
		lstyle = 'line-height:2.1;' .. lstyle
		rstyle = 'line-height:2.1;' .. rstyle
	end

	local html = mw.html.create()

	for i, v in pairs(orig) do
		html:
			tag('div')
				:tag('div')
					:cssText(lstyle)
					:node(lang.wrap(v, llang))
					:tag('br')
						:done()
					:done()
				:tag('div')
					:cssText(rstyle)
					:node(lang.wrap(tran[i], rlang))
					:tag('br')
						:done()
					:done()
	end
	
	-- Clear the floating
	html:tag('div'):cssText('clear:both')

	return tostring(html)
end

function p.lyrics(frame)
	local args = getArgs(frame, {wrappers='Template:LyricsKai'})
	return p._lyrics(args)
end

return p