Jump to content

Template:Fallback: Difference between revisions

From Meta, a Wikimedia project coordination wiki
Content deleted Content added
Zolo (talk | contribs)
try
Zolo (talk | contribs)
Undo revision 110105589 by Zolo (talk) ???
Line 67: Line 67:
}
}


function processarg(arg)
function returnarg(arg)
if arg == '~' then
if arg == '~' then
return ''
return ''
Line 75: Line 75:
return nil
return nil
end
end
end

function getfallback(args, lang, totest, tested)
if not tested then tested = {} end
for i, j in pairs(totest) do
for k, l in pairs(langlist[j]) do
if args[l] then
return args[l]
else if not tested[l] then
table.insert(totest, l)
end
end
table.insert(tested, j)
table.remove(totest, j)
end
if totest == {} then
return nil
end
return getfallback(args, lang, totest, tested)
end
end


Line 107: Line 88:
end
end
if args[lang] then
if args[lang] then
return processarg(args[lang])
return returnarg(args[lang])
end
end
if langlist[lang] then
if langlist[lang] then
tested = {} -- keep track of tested languages to avoid loops
fb = getfallback(args, lang, langlist[lang])
for i, j in pairs(langlist[lang]) do
if fb then
return processarg[bf]
if args[j] then
return returnarg(args[j])
end
end
end
end
end
end
if args.default then
if args.default then
return processarg(args.default)
return returnarg(args.default)
end
end
if args.en then
if args.en then
return processarg(args.en)
return returnarg(args.en)
end
end
return '[[Category:LangSwitch template without default version]]'
return '[[Category:LangSwitch template without default version]]'

Revision as of 09:01, 20 November 2013

Template documentation

This template was imported from commons:Template:Fallback without the here unusable documentation.


Use localised subpage for the user language with fallback to {{CONTENTLANGUAGE}}

Template parameters[Edit template data]

ParameterDescriptionTypeStatus
page1

Template name

Page namerequired
lang2

override user language on localised page

Default
{{int:Lang}}
Stringoptional

local p = {}
local langlist = {
 af = {'nl'}, 
 als = {'de'}, 
 arz = {'ar'}, 
 bar = {'de'}, 
 bexold = {'betarask'}, 
 br = {'fr'}, 
 ckb = {'fa'}, 
 co = {'fr'}, 
 crhcyrl = {'crh'}, 
 crhlatn = {'crh'}, 
 csb = {'pl'}, 
 deat = {'de'}, 
 dech = {'de'}, 
 deformal = {'de'}, 
 engb = {'en'}, 
 frp = {'fr'}, 
 frr = {'de'}, 
 fy = {'nl'}, 
 glk = {'fa'}, 
 hifdeva = {'hif'}, 
 hilatn = {'hif'}, 
 ht = {'fr'}, 
 ikecans = {'ik'}, 
 kkarab = {'kk'}, 
 kkcn = {'kk'}, 
 kkcyrl = {'kk'}, 
 kkkz = {'kk'}, 
 kklatn = {'kk'}, 
 kktr = {'kk'}, 
 ksh = {'de'}, 
 kuarab = {'ku'}, 
 kulatn = {'ku'}, 
 li = {'nl'}, 
 mg = {'fr'}, 
 mzn = {'fa'}, 
 nds = {'ndsnl', 'de'}, 
 ndsnl = {'nds', 'nl'}, 
 nlinformal = {'nl'}, 
 pdt = {'nds', 'de'}, 
 ptbr = {'pt'}, 
 ruggrek = {'ruq'}, 
 rulatn = {'ruq'}, 
 ruqcyrl = {'ruq'}, 
 srec = {'sr'}, 
 srel = {'sr'}, 
 szl = {'pl'}, 
 tgcyrl = {'tg'}, 
 tglatn = {'tg'}, 
 ttcyrl = {'tt'}, 
 ttlatn = {'tt'}, 
 ty = {'fr'}, 
 vec = {'it'}, 
 vls = {'nl'}, 
 wa = {'fr'}, 
 zea = {'nl'}, 
 zh = {'zhhans'}, 
 zhcn = {'zhhans'}, 
 zhhans = {'zhcn', 'zh'}, 
 zhhant = {'zh'}, 
 zhhk = {'zhhant'}, 
 zhmo = {'zhhant'}, 
 zhmy = {'zhhans'}, 
 zhsg = {'zhhans'}, 
 zhtw = {'zhhant'}
}

function returnarg(arg)
	if arg == '~' then
		return ''
	elseif arg then
		return arg
	else
		return nil
	end
end

function p.langSwitch(frame)
	local args = frame.args
	for i, j in pairs(args) do
		i = mw.ustring.gsub( i, "-", "")
	end
	if args.lang then
		lang = args.lang
	else 
		lang = frame:preprocess('{{int:lang}}')
	end
	if args[lang] then
		return returnarg(args[lang])
	end
	if langlist[lang] then
		tested = {} -- keep track of tested languages to avoid loops
		for i, j in pairs(langlist[lang]) do
			if args[j] then
				return returnarg(args[j])
			end
		end
	end
	if args.default then
		return returnarg(args.default)
	end
	if args.en then 
		return returnarg(args.en)
	end
	return '[[Category:LangSwitch template without default version]]'
end 
return p