Template:Fallback: Difference between revisions
Content deleted Content added
try |
|||
Line 67: | Line 67: | ||
} |
} |
||
function |
function returnarg(arg) |
||
if arg == '~' then |
if arg == '~' then |
||
return '' |
return '' |
||
Line 75: | Line 75: | ||
return nil |
return nil |
||
end |
end |
||
⚫ | |||
function getfallback(args, lang, totest, tested) |
|||
if not tested then tested = {} end |
|||
⚫ | |||
for k, l in pairs(langlist[j]) do |
|||
if args[l] then |
|||
⚫ | |||
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 |
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]) |
|||
⚫ | |||
if fb then |
|||
if args[j] then |
|||
⚫ | |||
⚫ | |||
end |
end |
||
end |
end |
||
end |
|||
if args.default then |
if args.default then |
||
return |
return returnarg(args.default) |
||
end |
end |
||
if args.en then |
if args.en then |
||
return |
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
This template was imported from commons:Template:Fallback without the here unusable documentation.
Use localised subpage for the user language with fallback to {{CONTENTLANGUAGE}}
Parameter | Description | Type | Status | |
---|---|---|---|---|
page | 1 | Template name | Page name | required |
lang | 2 | override user language on localised page
| String | optional |
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