跳转到内容

模組:Vgr

被永久保护的模块
维基百科,自由的百科全书

这是本页的一个历史版本,由Where was I last night?留言 | 贡献2016年12月10日 (六) 16:32 (为什么老是看不懂自己写的东西……)编辑。这可能和当前版本存在着巨大的差异。

local labelList = {
	
	{'KR', '-{zh-cn:韩国; zh-tw:南韓;}-'};
	{'JP', '日本'};
	{'WW', '全球'};
	{'NA', '北美'};
	{'PAL', '[[PAL区|PAL]]'};
	{'EU', '欧洲'};
	{'UK', '英国'};
	{'AU', '澳-{}-洲'}; -- 兼容{{Vgrelease new}}的使用参数
	{'AUS', '澳-{}-洲'}; -- 兼容{{Vgrelease}}的使用参数
	{'CN', '<abbr title="中国大陆">大陆</abbr>'};
	{'TWHK', '台港'};
	{'TW', '台湾'};
	{'HK', '香港'};
	{'SEA', '东南亚'};
	{'SG', '新加坡'};
	{'MY', '<abbr title="马来西亚">马来</abbr>'};
	{'INT', '[[国际版]]'};

}

require('Module:No globals')
local getArgs = require('Module:Arguments').getArgs
local p = {}

local function label(inp)
	
	if inp == nil then
		return '<span class="error">请检查输入</span>'
	end
	
	for i, v in ipairs(labelList) do
		if inp == v[1] then
			return v[2]
		end
	end

	if string.find(inp, '[A-Z][A-Z][A-Z]?') then
		return '<span class="error">请检查地区代码</span>'
	end

	return inp
end

local function data(inp)
	return require('Module:Chinese date')._main{inp, ['error']='ignore', ['suf']='yes'}
end

local function itemBuilder(args, l, d)
	
	if require('Module:Yesno')(args.nocc) then
		l, d = label(l), require('Module:WikitextLC').converted(data(d), {'zh-hans', 'zh-hant'})
	else
		l, d = label(l), data(d)
	end
	
	if args.s == '2' then
		return string.format('<li>%s(%s)</li>\n', d, l)
	end
	
	return string.format('<li>%s:%s</li>\n', l, d)
	
end

function p.main(frame)
	local args = getArgs(frame)
	return p._main(args)
end

function p._main(args)
	-- Main module code goes here.
	
	if args[1] == nil and args[2] and args[3] == nil then
		return '<ul style="list-style: none none; line-height: inherit; margin: 0px;">' .. data(args[2]) .. '</ul>'
	end
	
	local ret = ''
	
	for i, v in ipairs(labelList) do
		if args[v[1]] then
			ret = ret .. itemBuilder(args, v[1], args[v[1]])
		end
	end
		
	for i = 1, math.huge, 2 do
		if args[i] or args[i+1] then
			ret = ret .. itemBuilder(args, args[i], args[i+1])
		else
			break
		end
	end

	if ret ~= '' then
		ret = '<ul style="list-style: none none; line-height: inherit; margin: 0px;">\n' .. ret .. '</ul>'
	else
		ret = nil
	end
	
	return ret
end

return p