Module:Conversion-zh

From MediaWiki.org
Jump to navigation Jump to search
Module documentation
local l={}
local getArgs

local args
l.fallbackList={
	 ['zh']={'zh','zh-hans','zh-cn','zh-sg','zh-my','zh-hant','zh-tw','zh-hk','zh-mo'}
	,['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-my','zh-sg','zh'}
	,['zh-sg']={'zh-sg','zh-hans','zh-cn','zh-my','zh'}
	,['zh-my']={'zh-my','zh-hans','zh-cn','zh-sg','zh'}
	,['zh-tw']={'zh-tw','zh-hant','zh-hk','zh-mo','zh'}
	,['zh-hk']={'zh-hk','zh-hant','zh-tw','zh-mo','zh'}
	,['zh-mo']={'zh-mo','zh-hant','zh-tw','zh-hk','zh'}
}

function l._main(args, frame)
	local userlanguage=frame:callParserFunction{ name = 'int', args = {'lang'} }
	if ((userlanguage == 'zh') or 
		(userlanguage == 'zh-hans') or 
		(userlanguage == 'zh-hant') or 
		(userlanguage == 'zh-cn') or 
		(userlanguage == 'zh-sg') or 
		(userlanguage == 'zh-my') or 
		(userlanguage == 'zh-tw') or 
		(userlanguage == 'zh-hk') or 
		(userlanguage == 'zh-mo')) then
	else
		userlanguage = 'zh'
	end
	local fallback=l.fallbackList[userlanguage]
	for _,langArgName in ipairs(fallback)  do
		if 	args[langArgName] ~= nil then
			return args[langArgName]
		end
	end
	return ''
end

function l.main(frame)
	if not getArgs then
		getArgs = require('Module:Arguments').getArgs
	end
	args = getArgs(frame, {parentFirst=true})
        return l._main(args, frame)
end

return l