Module:Lan

From NeuroWiki
Revision as of 12:29, 1 November 2024 by Selfice (talk | contribs) (1 revision imported)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

此模块源于中文维基百科的同名模块,用于实现{{Lan}},主要用于无法通过常规字词转换语法正常转换的位置。

此模块并非意在取代常规字词转换。在能够使用常规语法和{{STConversion}}模板时请不要滥用此模块。


local p = {}

local merge

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

function p.call( args )
	local userLanguage = mw.getCurrentFrame():callParserFunction( 'int:module-lan-user-language' )
	local fallback = p.fallbackList[ userLanguage ]

	if fallback == nil then
		fallback = p.fallbackList[ 'zh' ]
	end

	for _, langArgName in ipairs( fallback ) do
		if args[ langArgName ] ~= nil then
			return args[ langArgName ]
		end
	end

	return ''
end

function p.main()
	local f = mw.getCurrentFrame()
	if not merge then
		merge = require('Module:ProcessArgs').merge
	end
	local args = merge(true)
	
	return p.call( args )
end

return p