LLWiki正在建设中,欢迎加入我们

模块:NoteTA

来自LLWiki
跳转到导航 跳转到搜索
Template-info.png 模块文档
这个文档嵌入模块:NoteTA/doc

说明

本模板用来在一个页面里,转换不同地区的翻译用语或指定特定的标题。加入此模板的页面顶部会出现noteTA(本页使用了标题或全文手工转换)标识。

使用方法

用法:

{{NoteTA
|T  = 标题
|G1 = 公共转换组1
|G2 = 公共转换组2
…
|Gn = 公共转换组n
|1  = 转换用词1
|2  = 转换用词2
…
|n = 转换用词n
}}

其中T是标题转换;n是序号数,最大为30。

G1至G30参数用来导入一些已定义好的公共转换组,比如LoveLive!学园偶像祭。直接引用公共转换组有很多好处,方便在一个领域和主题的条目中共同使用,方便维护,没有个数限制,可以实现单向转换。

local z = {}

function Tcode( args )
	if args.T == nil or args.T == '' then
		return ''
	end
	local div = mw.html.create( 'div' )
		:attr( 'class', 'noteTA-title' )
		:attr( 'data-noteta-code', args.T )
		:wikitext( '-{T|' .. args.T .. '}-' )
	if args.dt ~= nil and args.dt ~= '' then
		div:attr( 'data-noteta-desc', args.dt )
	end
	return tostring( div )
end

function group( name, frame )
	if name == nil or name == '' then
		return ''
	end
	local moduleTitle = mw.title.makeTitle( 'Module', 'CGroup/' .. name )
	if moduleTitle and moduleTitle.exists then
		local data = require( 'Module:CGroup/' .. name )
		local pieces = {}
		if data.content then
			for i, v in ipairs( data.content ) do
				if v.type == 'item' and v.rule then
					table.insert( pieces, '-{H|' .. v.rule .. '}-' )
				end
			end
			return tostring( mw.html.create( 'div' )
				:attr( 'data-noteta-group-source', 'module' )
				:attr( 'data-noteta-group', data.name or name )
				:wikitext( table.concat( pieces ) ) )
		end
	end
end

function Gcode( args, frame )
	local code = {}
	for i = 1, 30 do
		table.insert( code, group( args['G' .. i], frame ) )
	end
	code = table.concat( code )
	if code ~= '' then
		code = tostring( mw.html.create( 'div' )
				:attr( 'class', 'noteTA-group' )
				:wikitext( code ) )
		if args.G31 ~= nil then
			code = code .. '[[Category:NoteTA模板参数使用数量超过限制的页面|G]]'
		end
	end
	return code
end

function local_( i, code, desc )
	if code == nil or code == '' then
		return ''
	end
	local div = mw.html.create( 'div' )
		-- :attr( 'id', 'noteTA-local-' .. i )
		:attr( 'data-noteta-code', code )
		:wikitext( '-{H|' .. code .. '}-' )
	if desc ~= nil and desc ~= '' then
		div:attr( 'data-noteta-desc', desc )
	end
	return tostring( div )
end

function Lcode( args )
	local code = {}
	for i = 1, 30 do
		table.insert( code, local_( i, args[i], args['d' .. i] ) )
	end
	code = table.concat( code )
	if code ~= '' then
		code = tostring( mw.html.create( 'div' )
				:attr( 'class', 'noteTA-local' )
				:wikitext( code ) )
		if args[31] ~= nil then
			code = code .. '[[Category:NoteTA模板参数使用数量超过限制的页面|L]]'
		end
	end
	return code
end

function z.main( frame )
	local args
	if frame == mw.getCurrentFrame() then
		-- Being called from {{noteTA}}
		args = frame:getParent().args
	else
		-- Being called from another module
		args = frame
		frame = mw.getCurrentFrame()
	end
	local Tc = Tcode( args )
	local Gc = Gcode( args, frame )
	local Lc = Lcode( args )
	local code = Tc .. Gc .. Lc
	if code ~= '' then
		code = frame:extensionTag{
			name = 'indicator',
			content = '[[File:Zh conversion icon m.png|35px|本页使用了标题或全文手工转换|link=]]',
			args = { name = 'noteTA' },
		} ..
		tostring( mw.html.create( 'div' )
				:attr( 'id', 'mw-mobile-noteTA' )
				:addClass( 'mobileonly' )
				:cssText( 'position:absolute;right:0;top:-6.5em;' )
				:wikitext( '[[File:Zh conversion icon m.png|70px|本页使用了标题或全文手工转换|link=]]' ) ) ..
		tostring( mw.html.create( 'div' )
				:attr( 'id', 'noteTA' )
				:addClass( 'noteTA' )
				:wikitext( code ) )
		--if mw.title.getCurrentTitle():inNamespace( 'Template' ) then
			--code = code .. '[[Category:放置于模板的noteTA]]'
		--end
	end
	return code
end

return z