模块:Pending approval

来自Minecraft Wiki
Leo768留言 | 贡献2025年4月12日 (六) 11:05的版本 (這不是pa該負責的功能)
跳转到导航 跳转到搜索

此模块用于为{{Pending approval}}提供功能,具体用法见模板文档。

依赖项

[ 查看 | 编辑 | 历史 | 刷新 ]上述文档引用自Module:Pending approval/doc
local p = {}

local data = mw.loadData( [[Module:Pending approval/data]] )
local tr = require( [[Module:STConversion]] ).call

local template = [[<span style="opacity: 0.8;" class="explain minetip" title="译名尚未确定,请勿擅自改动">''%s''</span>]]
local convert = '-{%s|%s}-'

function p.pure( s, v )
	if v then
		return convert:format( v, template:format( s ) )
	else
		return template:format( s )
	end
end

function p.call( args )
	local target = ( args[1] or '' ) == '' and mw.title.getCurrentTitle().subpageText or args[1]
	local link = args[2]
	local entry = data[target]
	if entry then
		target = entry[1]
	end
	if link == '' then
		if ( args[1] or '' ) == '' then
			link = mw.title.getCurrentTitle().fullText
		else
			link = entry and entry.page or target
		end
	end
	local function out( s )
		if not link then
			return s
		elseif s == link then
			return '[[' .. s .. ']]'
		else
			return '[[' .. link .. '|' .. s .. ']]'
		end
	end
	local paText = template:format( out( target ) )
	if mw.isSubsting() then
		if entry and entry[2] and entry[3] and entry[4] then
			return out( entry[tonumber( args.target or 1 ) + 1] )
		else
			return '{{pa' ..
				( args[1] and ( '|' .. args[1] ) or '' ) ..
				( args[2] and ( '|' .. args[2] ) or '' ) ..
				'}}'
		end
	else
		local cat = ( mw.title.getCurrentTitle().isContentPage and not args.nocat ) and '[[Category:未确定的译名]]' or ''
		if entry then
			return tr {
				entry[2] and out( entry[2] ) or convert:format( 'zh-cn', paText ),
				entry[3] and out( entry[3] ) or convert:format( 'zh-tw', paText ),
				entry[4] and out( entry[4] ) or convert:format( 'zh-hk', paText ),
			} .. cat
		else
			return paText .. cat
		end
	end
end

function p.main( f )
	return p.call( f:getParent().args )
end

return p