跳转到内容

Module:Lan

维基语录,自由的名人名言录
文档图示 模块文档[查看] [编辑] [历史] [清除缓存]

本模块是{{lan}}的Lua实现。

local l = {}

l.fallbackList = {
	 ['zh']={'zh','zh-hant','zh-tw','zh-hk','zh-mo','zh-hans','zh-cn','zh-sg','zh-my'},
	 ['zh-hans']={'zh-hans','zh-cn','zh-sg','zh-my','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-hant']={'zh-hant','zh-tw','zh-hk','zh-mo','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)
	local frame = mw.getCurrentFrame()
	local userlanguage = frame:callParserFunction{ name = 'int', args = {'Conversionname'} }
	local fallback = l.fallbackList[userlanguage]
	if (not fallback) then
		fallback = l.fallbackList['zh']
	end
	for _,langArgName in ipairs(fallback)  do
		if args[langArgName] ~= nil then
			return args[langArgName]
		end
	end
	return ''
end

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

return l