Module:Conversion-zh: Difference between revisions

From TestWiki
Content added Content deleted
m (Sunny00217 moved page Module:Sandbox/conversion-zh to Module:Conversion-zh without leaving a redirect)
m (7 revisions imported: Import template for test)
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
local l={}
local this = {}
local getArgs


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


function l._main(args, frame)
function this._main(args)
local frame = mw.getCurrentFrame()
local userlanguage=frame:callParserFunction{ name = 'int', args = {'lang'} }
if ((userlanguage == 'zh') or
local userlanguage = frame:callParserFunction{ name = 'int', args = {'lang'} }
local fallback = this.fallbackList[userlanguage]
(userlanguage == 'zh-hans') or
if (not fallback) then
(userlanguage == 'zh-hant') or
fallback = this.fallbackList['zh']
(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
end
local fallback=l.fallbackList[userlanguage]
for _,langArgName in ipairs(fallback) do
for _,langArgName in ipairs(fallback) do
if args[langArgName] ~= nil then
if args[langArgName] ~= nil then
return args[langArgName]
return args[langArgName]
end
end
Line 38: Line 28:
end
end


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


return l
return this

Latest revision as of 16:43, 5 August 2020

Documentation for this module may be created at Module:Conversion-zh/doc

local this = {}

this.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 this._main(args)
	local frame = mw.getCurrentFrame()
	local userlanguage = frame:callParserFunction{ name = 'int', args = {'lang'} }
	local fallback = this.fallbackList[userlanguage]
	if (not fallback) then
		fallback = this.fallbackList['zh']
	end
	for _,langArgName in ipairs(fallback)  do
		if args[langArgName] ~= nil then
			return args[langArgName]
		end
	end
	return ''
end

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

return this