--\/ | ___ __| |_ _| | ___ _| | __ _ _ __ __ _/ ___|_ _(_) |_ ___| |__ | |\/| |/ _ \ / _` | | | | |/ _ (_) | / _` | '_ \ / _` \___ \ \ /\ / / | __/ __| '_ \ | | | | (_) | (_| | |_| | | __/_| |__| (_| | | | | (_| |___) \ V V /| | || (__| | | | |_| |_|\___/ \__,_|\__,_|_|\___(_)_____\__,_|_| |_|\__, |____/ \_/\_/ |_|\__\___|_| |_| |___/ Authors and maintainers:
local p =
--local function defaultCheck(args) if not args.en and not args.default then local err = 'LangSwitch Error: no default' if args.nocat
local function quickSwitch(args, arg) local err = defaultCheck(args) if err then return err end if arg
function p._langSwitch(args, lang) -- args: table of translations -- Return error if there is not default and no english version local err = defaultCheck(args) if err then return err end -- get the list of accepetable language (lang + those in lang's fallback chain) and check their content assert(lang, 'LangSwitch Error: no lang')
--local langList = --if not args[lang] then local langList = mw.language.getFallbacksFor(lang) table.insert(langList, 1, lang) table.insert(langList, math.max(#langList, 2), 'default') --end
for _, language in ipairs(langList) do lang = args[language] if lang
--langSwitch|en=text in english|pl=tekst po polsku|lang= }} Parameters: frame.args - table with translations by language frame.args.lang - desired language (often user's native language) Error Handling:function p.langSwitch(frame) -- version to be used from wikitext local args = frame.args -- if no expected args provided than check parent template/module args if args.en
nil and args.nocat
local lang = args.lang if not lang or not mw.language.isSupportedLanguage(lang) then lang = frame:callParserFunction("int", "lang") -- get user's chosen language end
-- Try quick switch local args1 = args[lang] if args1 and args1 ~= then return quickSwitch(args, args1) end
-- Allow input in format: -- with multiple languages mapping to a single value args1 = for name, value in pairs(args) do if value ~= and type(name)
return p