Template:Fallback: Difference between revisions
Content deleted Content added
No edit summary |
Leonidlednev (talk | contribs) m rvv Tag: Undo |
||
(123 intermediate revisions by 11 users not shown) | |||
Line 1: | Line 1: | ||
{{#ifexist: Template:{{{1|}}}/{{#if: {{{2|}}} |{{{2}}}|{{int:Lang}}}} |{{#if: {{{2|}}} |{{{2}}}|{{int:Lang}}}}|{{CONTENTLANGUAGE}}}}<noinclude> |
|||
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'} |
|||
} |
|||
{{documentation}} |
|||
function p.getfallback(args) -- process arguments from another function and sends them to findfallback to find the most appropriate language |
|||
</noinclude> |
|||
return p.findfallback(args, args.lang, langlist[args.lang], '') |
|||
end |
|||
function p.findfallback(args, lang, totest, tested) |
|||
-- totest = tables of languages whose fallbacks need to be examined |
|||
-- tested = string with language that have been examined |
|||
if args[lang] then |
|||
return args[lang] |
|||
end |
|||
for i, j in pairs(totest) do |
|||
if args[j] and args[j] ~= '' then |
|||
return args[j] |
|||
end |
|||
if langlist[j] then |
|||
for k, l in pairs(langlist[j]) do |
|||
table.insert(totest, l) |
|||
end |
|||
end |
|||
tested = tested .. ' ' .. j |
|||
end |
|||
for i, j in pairs(totest) do |
|||
if not string.find(tested, ' ' .. j) then |
|||
p.getfallback(args, lang, totest, tested) |
|||
end |
|||
end |
|||
if args[default] and arg[default] ~= '' then |
|||
return args[default] |
|||
end |
|||
if args[en] and arg[en] ~= '' then |
|||
return args[en] |
|||
end |
|||
return nil |
|||
end |
|||
function p.langSwitch(frame) |
|||
args = mw.getCurrentFrame():getParent().args |
|||
-- Return error if there is not default and no english version |
|||
if not args.en and not args.default and args.nocat ~= '1' then |
|||
return frame:expandTemplate{ title = "red", args = {'LangSwitch error: no default'}} .. '[[Category:LangSwitch template without default version]]' |
|||
end |
|||
-- get language (either stated one or user's default language) |
|||
if args.lang then |
|||
lang = args.lang |
|||
else |
|||
lang = frame:preprocess( "{{int:lang}}" ) |
|||
end |
|||
-- remove dashes from language names |
|||
for i in pairs(args) do |
|||
args[mw.ustring.gsub( i, "-", "")] = args[i] |
|||
end |
|||
-- gets the most appropriate language |
|||
text = p.getfallback(args) |
|||
if text == '~' then return '' end -- ~ indicates that no message should be shown in this language |
|||
return text |
|||
end |
|||
return p |
Latest revision as of 23:55, 18 June 2023
en
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 |