打开/关闭菜单
331
1.7K
131
11.8K
星露谷物语扩展百科
打开/关闭外观设置菜单
打开/关闭个人菜单
未登录
未登录用户的IP地址会在进行任意编辑后公开展示。

模块:STConversion

来自星露谷物语扩展百科
[ 创建 | 刷新 ]文档页面
当前模块文档缺失,需要扩充。
local p = {}

local fallbackString = mw.getCurrentFrame():extensionTag('nowiki')

local function item( variant, content )
	if not content then
		return ''
	end
	if string.match( content, '^()%s*$' ) then
		return variant .. ':' .. fallbackString .. ';'
	end
	return variant .. ':' .. string.match( content, '^.*%S' ) .. ';'
end

function p.call( args )
	return '-{' .. ( args.mode and ( args.mode .. '|' ) or '' ) ..
		item( 'zh-cn', args[ 'zh-cn' ] or args[ 1 ] ) ..
		item( 'zh-tw', args[ 'zh-tw' ] or args[ 2 ] ) ..
		item( 'zh-hk', ( args.closehkinherit and '' ) or args[ 'zh-hk' ] or args[ 3 ] ) ..
		'}-'
end

function p.main( f )
	local args = f
	if f == mw.getCurrentFrame() then
		args = f:getParent().args
	end
	return p.call( args )
end

p.fallbackList = {
	[ 'zh' ] = { 'zh', 'zh-hans', 'zh-hant', 'zh-cn', 'zh-tw', 'zh-hk', 'zh-sg', 'zh-mo', 'zh-my' },
	[ 'zh-hans' ] = { 'zh-hans', 'zh-cn', 'zh-sg', 'zh-my', 'zh' },
	[ 'zh-hant' ] = { 'zh-hant', 'zh-tw', 'zh-hk', 'zh-mo', 'zh' },
	[ 'zh-cn' ] = { 'zh-cn', 'zh-hans', 'zh-sg', 'zh-my', 'zh' },
	[ 'zh-tw' ] = { 'zh-tw', 'zh-hant', 'zh-hk', 'zh-mo', 'zh' },
	[ 'zh-hk' ] = { 'zh-hk', 'zh-hant', 'zh-tw', 'zh-mo', 'zh' },
	[ 'zh-sg' ] = { 'zh-sg', 'zh-hans', 'zh-cn', 'zh-my', 'zh' },
	[ 'zh-mo' ] = { 'zh-mo', 'zh-hant', 'zh-hk', 'zh-tw', 'zh' },
	[ 'zh-my' ] = { 'zh-my', 'zh-hans', 'zh-cn', 'zh-sg', 'zh' }
}

function p.lan( args )
	local variants = {}
	
	local codes = { 'zh', 'zh-hans', 'zh-hant', 'zh-cn', 'zh-tw', 'zh-hk', 'zh-sg', 'zh-mo', 'zh-my' }
	
	for _, code in ipairs(codes) do
		if args[code] then
			table.insert(variants, item(code, args[code]))
		end
	end
	
	if #variants == 0 then
		return ''
	end
	
	return '-{' .. table.concat(variants, '') .. '}-'
end

return p