本WIKI由Legend frog(留言)于2023年10月8日申请开通,除首页外编辑权限开放。祝贺《偶像大师 灰姑娘女孩》企划面世13周年!欢迎各位灰姑娘制作人加入交流群:327967793;如有急切的审核需要则请在加群信息附带“-审核”等字样

全站通知:

模块:Lyrics

来自偶像大师灰姑娘女孩WIKI_BWIKI_哔哩哔哩
跳到导航 跳到搜索

该模块提供了一种简便的创建大段带翻译歌词的方法,对应的模板是{{LyricsKai}}。



local p = {}

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

function p._lyrics(args, hookTrigger, customArgs)
	local original = args.original or ''
	local translated = args.translated or ''
	if hookTrigger then
		original, translated = hookTrigger('preSplit', original, translated, customArgs)
	end

	local tran = {}
	local iter_tran = mw.ustring.gmatch(translated..'\n', '([^\n]*)\n')
	for val_tran in iter_tran do
		table.insert(tran, val_tran)
	end
	local orig = {}
	local iter_orig = mw.ustring.gmatch(original..'\n', '([^\n]*)\n')
	for val_orig in iter_orig do
		table.insert(orig, val_orig)
	end

	local llang = args.llang or ''
	local rlang = args.rlang or ''
	local lstyle = args.lstyle or ''
	local rstyle = args.rstyle or ''

	local html = mw.html.create('div')
					:addClass('Lyrics')
					:css('width', args.width)
					:cssText(args.containerstyle or '')

	if ((args['hasRuby'] or '') ~= '') or (not args.colorsMode and (args.original or ''):find('<ruby')) then
		html:addClass('Lyrics-has-ruby')
	else
		html:addClass('Lyrics-no-ruby')
	end

	local hastran = true
	if #tran == 1 and tran[1] == '' then
		hastran = false
	else
		html:addClass('Lyrics-has-translate')
	end

	if hookTrigger then
		hookTrigger('preParse', orig, hastran and tran or false, customArgs)
	end

	local lines = {}
	local len = math.max(#orig, #tran)
	for i=1, len do
		local line = mw.html.create('div'):addClass('Lyrics-line')
			:tag('div')
				:addClass('Lyrics-original')
				:cssText(lstyle)
				:node(lang.wrap(orig[i] or '', rlang))
				:done()
		if hastran then
			line:tag('div')
				:addClass('Lyrics-translated')
				:cssText(rstyle)
				:node(lang.wrap(tran[i] or '', rlang))
				:done()
		end
		table.insert(lines, tostring(line))
	end

	if hookTrigger then
		hookTrigger('postParse', lines, customArgs)
	end
	html:node(table.concat(lines))
	-- Clear the floating
	html:tag('div'):cssText('clear:both')
	html = tostring(html)

	if hookTrigger then
		html = hookTrigger('preOutput', html, customArgs)
	end

	local copyright = ''
	local frame = mw.getCurrentFrame()
	local LDC = frame:callParserFunction{ name = '#var', args = { 'LDC', '0' } }
	if LDC ~= '1' and args.override ~= '1' then
		copyright = '<small>本段落中所使用的歌词,其著作权属于' .. (args.author or '原权利人') .. ',仅以介绍为目的引用。</small>'
	elseif LDC == '1' and args.override == '1' then
		copyright = frame:expandTemplate{ title = 'ac', args = { '不必要使用override参数的音乐条目' } }
	end
--	local css = frame:extensionTag{ name = 'templatestyles', args = { src = 'Template:LyricsKai/styles.css' } }
	local transCat=''
	if hastran == false then
		transCat="[[Category:需要翻译的条目]]"
	end
--	return copyright .. css .. html
	return copyright .. html..transCat
end

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

return p