-- From [[zhmoe:Module:Lyrics]], for [[Template:LyricsKai]]
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 ''):match('^(.-)%s*$'), '\n')
local tran = mw.text.split((args.translated or ''):match('^(.-)%s*$'), '\n')
local llang = args.llang or 'ja'
local rlang = args.rlang or 'zh'
local lstyle = args.lstyle or ''
local rstyle = args.rstyle or ''
local html = mw.html.create('div')
:addClass('Lyrics')
:cssText('width:'..(args.width or 'calc(100% - '..(args.reserveWidth or '0px')..');'))
:cssText(args.containerstyle or '')
-- 适用Template:LyricsKai/colors
if args['colorsMode'] then
local getArray = require('Module:var-array').get
orig = getArray('lyricsKai/colors.original')
if args['colorsMode'] == '2' then
tran = getArray('lyricsKai/colors.translated')
end
end
if (args.original or ''):find('<ruby') or (args['hasRuby'] or ''):find('[^%s]') then
html:addClass('Lyrics-has-ruby')
else
html:addClass('Lyrics-no-ruby')
end
local len = math.max(#orig, #tran)
for i=1,len do
html
:tag('div')
:addClass('Lyrics-line')
:tag('div')
:addClass('Lyrics-original')
:cssText(lstyle)
:node(lang.wrap(orig[i] or '', llang))
:done()
:tag('div')
:addClass('Lyrics-translated')
:cssText(rstyle)
:node(lang.wrap(tran[i] or '', rlang))
:done()
end
-- Clear the floating
html:tag('div'):cssText('clear:both')
local css = mw.getCurrentFrame():extensionTag{ name = 'templatestyles', args = { src = 'Template:LyricsKai/styles.css' } }
return css .. tostring(html)
end
function p.lyrics(frame)
local args = getArgs(frame, {wrappers='Template:LyricsKai'})
return p._lyrics(args)
end
return p