Module:Languages

From Wikimedia Commons, the free media repository
Jump to: navigation, search
Lua
CodeDiscussionEditHistoryQuick tests passed DocumentationSubpagesLinksTestsResultsSandbox All modules

See inline documentation

Supported languages (mappings in "MediaWiki:Lang/code" for {{int:lang}}, and their current native names)
(aa) Qafár af
(ab) Аҧсшәа
(ace) Acèh
(ady) адыгабзэ
(ady-cyrl) адыгабзэ
(aeb) تونسي/Tûnsî
(aeb-arab) تونسي
(aeb-latn) Tûnsî
(af) Afrikaans
(ak) Akan
(aln) Gegë
(als) Alemannisch
(am) አማርኛ
(an) aragonés
(ang) Ænglisc
(anp) अङ्गिका
(ar) العربية
(arc) ܐܪܡܝܐ
(arn) mapudungun
(arq) جازايرية
(ary) Maġribi
(arz) مصرى
(as) অসমীয়া
(ase) American sign language
(ast) asturianu
(av) авар
(avk) Kotava
(awa) अवधी
(ay) Aymar aru
(az) azərbaycanca
(azb) تۆرکجه
(ba) башҡортса
([[:MediaWiki:Lang/ban]]) Basa Bali
(bar) Boarisch
(bat-smg) žemaitėška
(bbc) Batak Toba
(bbc-latn) Batak Toba
(bcc) جهلسری بلوچی
(bcl) Bikol Central
(be) беларуская
(be-tarask) беларуская (тарашкевіца)‎
(be-x-old) беларуская (тарашкевіца)‎
(bg) български
(bgn) روچ کپتین بلوچی
(bh) भोजपुरी
(bho) भोजपुरी
(bi) Bislama
(bjn) Bahasa Banjar
(bm) bamanankan
(bn) বাংলা
(bo) བོད་ཡིག
(bpy) বিষ্ণুপ্রিয়া মণিপুরী
(bqi) بختیاری
(br) brezhoneg
(brh) Bráhuí
(bs) bosanski
(bto) Iriga Bicolano
(bug) ᨅᨔ ᨕᨘᨁᨗ
(bxr) буряад
(ca) català
(cbk-zam) Chavacano de Zamboanga
(cdo) Mìng-dĕ̤ng-ngṳ̄
(ce) нохчийн
(ceb) Cebuano
(ch) Chamoru
(cho) Choctaw
(chr) ᏣᎳᎩ
(chy) Tsetsêhestâhese
(ckb) کوردیی ناوەندی
(co) corsu
(cps) Capiceño
(cr) Nēhiyawēwin / ᓀᐦᐃᔭᐍᐏᐣ
(crh) qırımtatarca
(crh-cyrl) къырымтатарджа (Кирилл)‎
(crh-latn) qırımtatarca (Latin)‎
(cs) čeština
(csb) kaszëbsczi
(cu) словѣньскъ / ⰔⰎⰑⰂⰡⰐⰠⰔⰍⰟ
(cv) Чӑвашла
(cy) Cymraeg
(da) dansk
(de) Deutsch
(de-at) Österreichisches Deutsch
(de-ch) Schweizer Hochdeutsch
(de-formal) Deutsch (Sie-Form)‎
(diq) Zazaki
(dsb) dolnoserbski
(dtp) Dusun Bundu-liwan
(dty) डोटेली
(dv) ދިވެހިބަސް
(dz) ཇོང་ཁ
(ee) eʋegbe
(egl) Emiliàn
(el) Ελληνικά
(eml) emiliàn e rumagnòl
(en) English
(en-ca) Canadian English
(en-gb) British English
(eo) Esperanto
(es) español
(et) eesti
(eu) euskara
(ext) estremeñu
(fa) فارسی
(ff) Fulfulde
(fi) suomi
(fit) meänkieli
(fiu-vro) Võro
(fj) Na Vosa Vakaviti
(fo) føroyskt
(fr) français
(frc) français cadien
(frp) arpetan
(frr) Nordfriisk
(fur) furlan
(fy) Frysk
(ga) Gaeilge
(gag) Gagauz
(gan) 贛語
(gan-hans) 赣语(简体)‎
(gan-hant) 贛語(繁體)‎
(gd) Gàidhlig
(gl) galego
(glk) گیلکی
(gn) Avañe'ẽ
(gom) गोंयची कोंकणी / Gõychi Konknni
(gom-deva) गोंयची कोंकणी
(gom-latn) Gõychi Konknni
([[:MediaWiki:Lang/gor]]) Bahasa Hulontalo
(got) 𐌲𐌿𐍄𐌹𐍃𐌺
(grc) Ἀρχαία ἑλληνικὴ
(gsw) Alemannisch
(gu) ગુજરાતી
(gv) Gaelg
(ha) Hausa
(hak) 客家語/Hak-kâ-ngî
(haw) Hawaiʻi
(he) עברית
(hi) हिन्दी
(hif) Fiji Hindi
(hif-latn) Fiji Hindi
(hil) Ilonggo
(ho) Hiri Motu
(hr) hrvatski
(hrx) Hunsrik
(hsb) hornjoserbsce
(ht) Kreyòl ayisyen
(hu) magyar
(hy) Հայերեն
(hz) Otsiherero
(ia) interlingua
(id) Bahasa Indonesia
(ie) Interlingue
(ig) Igbo
(ii) ꆇꉙ
(ik) Iñupiak
(ike-cans) ᐃᓄᒃᑎᑐᑦ
(ike-latn) inuktitut
(ilo) Ilokano
(inh) ГӀалгӀай
(io) Ido
(is) íslenska
(it) italiano
(iu) ᐃᓄᒃᑎᑐᑦ/inuktitut
(ja) 日本語
(jam) Patois
(jbo) la .lojban.
(jut) jysk
(jv) Basa Jawa
(ka) ქართული
(kaa) Qaraqalpaqsha
(kab) Taqbaylit
(kbd) Адыгэбзэ
(kbd-cyrl) Адыгэбзэ
(kg) Kongo
(khw) کھوار
(ki) Gĩkũyũ
(kiu) Kırmancki
(kj) Kwanyama
(kk) қазақша
(kk-arab) قازاقشا (تٴوتە)‏
(kk-cn) قازاقشا (جۇنگو)‏
(kk-cyrl) қазақша (кирил)‎
(kk-kz) қазақша (Қазақстан)‎
(kk-latn) qazaqşa (latın)‎
(kk-tr) qazaqşa (Türkïya)‎
(kl) kalaallisut
(km) ភាសាខ្មែរ
(kn) ಕನ್ನಡ
(ko) 한국어
(koi) Перем Коми
(ko-kp) 한국어 (조선)
(kr) Kanuri
(krc) къарачай-малкъар
(kri) Krio
(krj) Kinaray-a
([[:MediaWiki:Lang/krl]]) karjal
(ks) कॉशुर / کٲشُر
(ks-arab) کٲشُر
(ks-deva) कॉशुर
(ksh) Ripoarisch
(ku) Kurdî
(ku-arab) كوردي (عەرەبی)‏
(ku-latn) Kurdî (latînî)‎
(kv) коми
(kw) kernowek
(ky) Кыргызча
(la) Latina
(lad) Ladino
(lb) Lëtzebuergesch
(lbe) лакку
(lez) лезги
(lfn) Lingua Franca Nova
(lg) Luganda
(li) Limburgs
(lij) Ligure
(liv) Līvõ kēļ
(lki) لەکی‎
(lmo) lumbaart
(ln) lingála
(lo) ລາວ
(loz) Silozi
(lrc) لۊری شومالی
(lt) lietuvių
(ltg) latgaļu
(lus) Mizo ţawng
(luz) لئری دوٙمینی
(lv) latviešu
(lzh) 文言
(lzz) Lazuri
(mai) मैथिली
(map-bms) Basa Banyumasan
(mdf) мокшень
(mg) Malagasy
(mh) Ebon
(mhr) олык марий
(mi) Māori
(min) Baso Minangkabau
(mk) македонски
(ml) മലയാളം
(mn) монгол
(mo) молдовеняскэ
(mr) मराठी
(mrj) кырык мары
(ms) Bahasa Melayu
(mt) Malti
(mus) Mvskoke
(mwl) Mirandés
(my) မြန်မာဘာသာ
(myv) эрзянь
(mzn) مازِرونی
(na) Dorerin Naoero
(nah) Nāhuatl
(nan) Bân-lâm-gú
(nap) Napulitano
(no) norsk bokmål
(nds) Plattdüütsch
(nds-nl) Nedersaksies
(ne) नेपाली
(new) नेपाल भाषा
(ng) Oshiwambo
(niu) Niuē
(nl) Nederlands
(nl-informal) Nederlands (informeel)‎
(nn) norsk nynorsk
(no) norsk bokmål
(nov) Novial
(nrm) Nouormand
(nso) Sesotho sa Leboa
(nv) Diné bizaad
(ny) Chi-Chewa
(oc) occitan
(olo) Livvinkarjala
(om) Oromoo
(or) ଓଡ଼ିଆ
(os) Ирон
(pa) ਪੰਜਾਬੀ
(pag) Pangasinan
(pam) Kapampangan
(pap) Papiamentu
(pcd) Picard
(pdc) Deitsch
(pdt) Plautdietsch
(pfl) Pälzisch
(pi) पालि
(pih) Norfuk / Pitkern
(pl) polski
(pms) Piemontèis
(pnb) پنجابی
(pnt) Ποντιακά
(prg) Prūsiskan
(ps) پښتو
(pt) português
(pt-br) português do Brasil
(qu) Runa Simi
(qug) Runa shimi
(rgn) Rumagnôl
(rif) Tarifit
(rm) rumantsch
(rmy) Romani
(rn) Kirundi
(ro) română
(roa-rup) armãneashti
(roa-tara) tarandíne
(ru) русский
(rue) русиньскый
(rup) armãneashti
(ruq) Vlăheşte
(ruq-cyrl) Влахесте
(ruq-latn) Vlăheşte
(rw) Kinyarwanda
(sa) संस्कृतम्
(sah) саха тыла
(sat) Santali
(sc) sardu
(scn) sicilianu
(sco) Scots
(sd) سنڌي
(sdc) Sassaresu
(sdh) کوردی خوارگ
(se) sámegiella
(sei) Cmique Itom
(ses) Koyraboro Senni
(sg) Sängö
(sgs) žemaitėška
(sh) srpskohrvatski / српскохрватски
(shi) Tašlḥiyt/ⵜⴰⵛⵍⵃⵉⵜ
(shi-latn) Tašlḥiyt
(shi-tfng) ⵜⴰⵛⵍⵃⵉⵜ
([[:MediaWiki:Lang/shn]]) ၽႃႇသႃႇတႆး
(si) සිංහල
(simple) Simple English
(sk) slovenčina
(sl) slovenščina
(sli) Schläsch
(sm) Gagana Samoa
(sma) Åarjelsaemien
(sn) chiShona
(so) Soomaaliga
(sq) shqip
(sr) српски / srpski
(sr-ec) српски (ћирилица)‎
(sr-el) srpski (latinica)‎
(srn) Sranantongo
(ss) SiSwati
(st) Sesotho
(stq) Seeltersk
(su) Basa Sunda
(sv) svenska
(sw) Kiswahili
(szl) ślůnski
(ta) தமிழ்
(tcy) ತುಳು
(te) తెలుగు
(tet) tetun
(tg) тоҷикӣ
(tg-cyrl) тоҷикӣ
(tg-latn) tojikī
(th) ไทย
(ti) ትግርኛ
(tk) Türkmençe
(tl) Tagalog
(tly) толышә зывон
(tn) Setswana
(to) lea faka-Tonga
(tokipona) Toki Pona
(tpi) Tok Pisin
(tr) Türkçe
(tru) Ṫuroyo
(ts) Xitsonga
(tt) татарча/tatarça
(tt-cyrl) татарча
(tt-latn) tatarça
(tum) chiTumbuka
(tw) Twi
(ty) reo tahiti
(tyv) тыва дыл
(tzm) ⵜⴰⵎⴰⵣⵉⵖⵜ
(udm) удмурт
(ug) ئۇيغۇرچە / Uyghurche
(ug-arab) ئۇيغۇرچە
(ug-latn) Uyghurche
(uk) українська
(ur) اردو
(uz) oʻzbekcha/ўзбекча
(uz-cyrl) ўзбекча
(uz-latn) oʻzbekcha
(ve) Tshivenda
(vec) vèneto
(vep) vepsän kel’
(vi) Tiếng Việt
(vls) West-Vlams
(vmf) Mainfränkisch
(vo) Volapük
(vot) Vaďďa
(vro) Võro
(wa) walon
(war) Winaray
(wo) Wolof
(wuu) 吴语
(xal) хальмг
(xh) isiXhosa
(xmf) მარგალური
(yi) ייִדיש
(yo) Yorùbá
(yue) 粵語
(za) Vahcuengh
(zea) Zeêuws
(zh) 中文
(zh-classical) 文言
(zh-cn) 中文(中国大陆)‎
(zh-hans) 中文(简体)‎
(zh-hant) 中文(繁體)‎
(zh-hk) 中文(香港)‎
(zh-min-nan) Bân-lâm-gú
(zh-mo) 中文(澳門)‎
(zh-my) 中文(马来西亚)‎
(zh-sg) 中文(新加坡)‎
(zh-tw) 中文(台灣)‎
(zh-yue) 粵語
(zu) isiZulu
The previous list was generated by:
{{#invoke:Languages|forEachLanguage|preprocess=yes|pattern=<nowiki/>
:<small>([[MediaWiki:Lang/$lc|<tt title="{{((}}#language:$lc{{!}}en{{))}}">{{((}}msgnw:MediaWiki:Lang/$lc{{))}}</tt>]])</small> <bdi lang="$lc" class="autonym lang-$lc">{{((}}#language:$lc{{))}}</bdi>
}}

Code

--[=[
Not globally exposed. Internal function only.

language_subpages( frame, transform, options )
Parameters
    frame:     The frame that was passed to the method invoked. The first argument or the page argument will be respected.
    transform: A transform function. Example: function( basepagename, subpagename, code, langname ) end
    options:   An object with options. Example: { abort= { on=function() end, time=0.8 }  }
        Following options are available:
        abort: Aborts iterating over the subpages if one of the conditions is met. If the process is aborted, nil is returned!
            on: Function to be called if an abort-condition was met.
            cycles: The maximum number of subpages to run over.
            time: Maximum time to spend running over the subpages.

]=]
function language_subpages( frame, transform, options )
    local args, pargs, options = frame.args, ( frame:getParent() or {} ).args or {}, options or {};
    local title = args.page or args[1] or pargs.page or pargs[1] or "";
    local abort = options.abort or {};
    local at, clock = type( abort.on ), os.clock();
    local ac = function()
        if  at == 'function' or ( at == 'table' and getmetatable(abort.on).__call ) then
            abort.on();
        end
    end
    local tt = type( transform );
    local page = require( 'Module:Page' );

    title = page.clean(title);

    if tt == 'function' or ( tt == 'table' and getmetatable(transform).__call ) then
        local fetch, pages, langcode, langname = mw.language.fetchLanguageName, {};
--[==[

     / \
    / | \
   /  ·  \
   ¯¯¯¯¯¯¯
   Page.subpages() no longer works because it attempted to parse the HTML content generated by
   calling the parser function "Special:Prefixindex:" which is no longer expanded in Lua but
   converted to a "stripped tag" (containing a unique identifier surrounded by ASCII DEL characters)
   representing the tag name and its parameters.
   The actual expansion of stripped tags can no longer be performed in Lua.
   Now unstripping these tags just kills ALL these tags (except "wiki" tags) instead of performing
   their expansion by running the extension code. Only MediaWiki can unstrip these tags in texts after
   they have been returned by Lua.
   For this reason, page.subpages() is now completely empty (Module:Page no longer works).
   This cannot be bypassed, except by using a Scribunto extension library if lifting the limits set by mw.unstrip.
   Note that "Special:Prefixindex:" is also costly, even if it just requires a single database query to
   get all subpages, instead of one costly #ifexist or one costly mw.title() property reading per
   tested subpage to know if it exists.
   For now there's still no reliable way to get a list of subpages, or performing queries similar to
   the [[Special:Prefixindex]] page or list members of a category like when viewing a category page.
   Ideally, there should exist a method for such queries on Title objects returned by the mw.title library;
   but for now there's none.
   In Lua now, the only expansion possible with an immediate effect is the expansion of standard templates,
   all special tags or special pages, or parser function extensions do not work (Only the #expr parser
   function is supported by using an external Scribunto library).
--]==]
        for pg in page.subpages( title, { ignoreNS=true } ) do
            if abort.cycles then
                abort.cycles = abort.cycles - 1
                if 0 == abort.cycles then return ac()  end
            end
            if abort.time then
                if (os.clock() - clock) > abort.time then return ac()  end
            end
            if mw.ustring.len( pg ) <= 12 then
                langcode = string.lower( pg );
                langname = fetch( langcode );
                if langname ~= '' then
                    table.insert( pages, transform( title, pg, langcode, langname ) );
                end
            end
        end
        return pages;
    end
    return {};
end

function cloneArgs(frame)
    local args, pargs = {}, {}
    for k,v in pairs( frame.args ) do args[k] = v end
    if frame:getParent() then
        for k,v in pairs( frame:getParent().args ) do pargs[k] = v end
    end
    return args, pargs;
end



local p = {};

--[=[
Usage:
{{#invoke:languages|internal|Template:Adjective}}
]=]
function p.internal(frame)
    pages = language_subpages( frame, function( title, page, code, name )
        return mw.ustring.format( '<span lang="%s" xml:lang="%s" class="language lang-%s"><bdi>[[%s/%s|%s]]</bdi></span>',
            code, code, code, title, page, name
        );
    end);
    return table.concat( pages, '&nbsp;·&nbsp;' );
end

--[=[
Usage:
{{#invoke:languages|external|Template:Adjective}}
]=]
function p.external(frame)
    pages = language_subpages( frame, function( title, page, code, name )
        return mw.ustring.format( '<span lang="%s" xml:lang="%s" class="language lang-%s"><bdi>[%s/%s %s]</bdi></span>',
            code, code, code, tostring( mw.uri.fullUrl( title ) ), page:gsub( ' ', '_' ), name
        );
    end);
    return table.concat( pages, '&nbsp;| ' );
end

--[=[
forEachLanguage

This function iterates over all language codes known to MediaWiki based on a maintained list
replacing patterns in a pattern-string for each language

Usage
{{#invoke:Languages|forEachLanguage
  |pattern=patternstring
  |before=string to insert before iteration
  |after=string added after iteration
  |sep=separator string between iterations
  |inLang=langcode used for $lnTrP and $lnTrUC1
}}

Parameters
    pattern: A pattern string which is processed for each language and which is concatenated at the end and returned as one string
    before: A string that is inserted before the concatenated result
    after: A string that is inserted after the concatenated result
    sep: A string that is inserted between each line created from the pattern while iterating (like ProcessedPattern_sep_ProcessedPattern_sep_ProcessedPattern)
    inLang: Langcode to use for $lnTrP and $lnTrUC1
    preprocess: if set to a non-empty value, the output will be preprocessed before being returned.

Warning
    The output is still not prepreprocessed by default: so parser functions and magic keywords generated by the pattern are still not executed and replaced,
    and template transclusions are still not expanded (see examples in other functions in this module).
    When using this function directly from a MediaWiki page or template, this means it is only possible to use patterns generating basic MediaWiki formatting
    or HTML tags. It you want the output to be preprocessed (in the given frame), set the preprocess parameter to a non-empty string.
    
Patterns
    $lc - language code such as en or de
    $lnP - language name in own language (autonym)
    $lnUC1 - language name in own language (autonym), first letter upper case
    $lnTrP - language name translated to the language requested by language code passed to inLang
    $lnTrUC1 - language name translated to the language requested by language code passed to inLang, first letter upper case

Example
    {{#invoke:Languages|forEachLanguage|pattern=<span lang="$lc" xml:lang="$lc" class="language lang-$lc">[[Page/$lc|$lnP]]</span>}}
]=]

-- =p.forEachLanguage({ args= { pattern = "$lc - $lnTrP\n", inLang = "en" } })
function p.forEachLanguage(frame)
    local l = require( "Module:Languages/List" )

    local ret = {}
    local lang    = mw.language
    local line
    local pattern = frame.args.pattern   or frame.args[1] or ""
    local prefix  = frame.args.before    or frame.args[2] or ""
    local postfix = frame.args.after     or frame.args[3] or ""
    local sep     = frame.args.sep       or frame.args.separator or frame.args[4] or ""
    local inLang  = frame.args.inLang    or frame.args[5] or nil
    local preprocess = frame.args.preprocess or frame.args[6] or ""

    local langNameUCFirstReq           = not not pattern:find( "$lnUC1", 1, true )
    local langNameReq                  = not not pattern:find( "$lnP", 1, true ) or langNameUCFirstReq
    local langNameTranslatedUCFirstReq = not not pattern:find( "$lnTrUC1", 1, true )
    local langNameTranslatedReq        = not not pattern:find( "$lnTrP", 1, true ) or langNameTranslatedUCFirstReq
    local contentLangInstance = mw.language.getContentLanguage()
    local inLangLangInstance
    local l = mw.language.fetchLanguageNames() -- autonyms
    local lTr
    local lcIdList = require( 'Module:Languages/List' ).getSortedList( l )

    if langNameTranslatedReq then
        inLangLangInstance = --[==[
            mw.getLanguage( inLang ) -- Quota hit in :ucfirst() if using too many langInstances
            --]==] contentLangInstance
        lTr = mw.language.fetchLanguageNames( inLang ) -- translated names
    end

    for _, lcId in pairs( lcIdList ) do
        local subst = lcId:gsub('%%', '%%%%')
        line = pattern:gsub( "%$lc", subst )
        local langName, langInstance
        -- autonym (name of lcId in locale lcId)
        if langNameReq then
            langName = l[lcId]
            subst = langName:gsub('%%', '%%%%')
            line = line:gsub( "%$lnP", subst )
        end
        if langNameUCFirstReq then
            langInstance = --[==[
                mw.getLanguage( lcId ) -- Quota hit in :ucfirst() if using too many langInstances
                --]==] contentLangInstance
            langName = langInstance:ucfirst( langName )
            subst = langName:gsub('%%', '%%%%')
            line = line:gsub( "%$lnUC1", subst )
        end

        -- translated name (name of lcId in locale inLang)
        if langNameTranslatedReq then
            langName = lTr[lcId]
            subst = langName:gsub('%%', '%%%%')
            line = line:gsub( "%$lnTrP", subst )
        end
        if langNameTranslatedUCFirstReq then
            langName = inLangLangInstance:ucfirst( langName )
            subst = langName:gsub('%%', '%%%%')
            line = line:gsub( "%$lnTrUC1", subst )
        end

        table.insert(ret, line)
    end
    ret = prefix .. table.concat( ret, sep ) .. postfix
    if preprocess ~= '' then
        ret = frame:preprocess(ret)
    end
    return ret
end

--[=[
 Provide logic for [[Template:Lle]] (Language Links external, to be substituted)
]=]
function p.lle(frame)
    local ret
    local pattern = "{{<includeonly/>subst:#ifexist:{{{1}}}/$lc|[{{fullurl:{{{1}}}/$lc}} $lnUC1]&nbsp;{{<includeonly/>subst:!}} <!--\n-->}}"
    ret = p.forEachLanguage({ args= { pattern = pattern } })
    ret = frame:preprocess(ret)
    return ret
end

--[=[
 Provide logic for [[Template:Ll]] (Language Links, to be substituted)
]=]
function p.ll(frame)
    local ret
    local pattern = "{{<includeonly/>subst:#ifexist:{{{1}}}/$lc|[[{{{1}}}/$lc{{<includeonly/>subst:!}}$lnUC1]]&nbsp;{{<includeonly/>subst:!}} <!--\n-->}}"
    ret = p.forEachLanguage({ args= { pattern = pattern } })
    ret = frame:preprocess(ret)
    return ret
end


--------------------------------------------------------
--- Different approaches for [[Template:Lang links]] ---
--------------------------------------------------------

--[=[
 Provide logic for [[Template:Lang links]]
 Using a cute Hybrid-Method:
    First check the subpages which is quite fast; if there are too many fall back to checking for each language page individually
]=]

-- =p.langLinksNonExpensive({ args= { page='Commons:Picture of the Year/2010' }, getParent=function() end })
-- =p.langLinksNonExpensive({ args= { page='Main Page' }, getParent=function() end })
-- =p.langLinksNonExpensive({ args= { page='Template:No_source_since' }, getParent=function() end })
-- =p.langLinksNonExpensive({ args= { page='MediaWiki:Gadget-HotCat' }, getParent=function() end })
function p.langLinksNonExpensive(frame)
    local args, pargs = frame.args, ( frame:getParent() or {} ).args or {};
    local title = args.page or args[1] or pargs.page or pargs[1] or "";
    local contentLangInstance = mw.language.getContentLanguage();
    local pages2
    if frame.preprocess == nil then
        frame = mw.getCurrentFrame()
    end
    --[==[
    local options = { abort= { time=3.5, on=function()
            pages2 = p.forEachLanguage({ args= { pattern = '{{#ifexist:' .. title .. '/$lc|[[' .. title .. '/$lc|$lnUC1]]&nbsp;&#124;&#32;}}' } })
        end } }
    local pages = language_subpages( frame, function( basepagename, subpagename, code, langname )
        return mw.ustring.format( '<span lang="%s" xml:lang="%s" class="language lang-%s" style="white-space:nowrap"><bdi>[[%s/%s|%s]]</bdi></span>&nbsp;| ',
            code, code, code, basepagename, subpagename, contentLangInstance:ucfirst( langname ) )
    end, options );
    return pages2 and frame:preprocess(pages2) or table.concat(pages, '');
    ]==]
    return frame:preprocess( p.forEachLanguage({ args= { pattern = '{{#ifexist:' .. title .. '/$lc|[[' .. title .. '/$lc|$lnUC1]]&nbsp;&#124;&#32;}}' } }) )
end

---------------------------------------------------------
----------------- [[Template:Autolang]] -----------------
---------------------------------------------------------
--[[
  Works like {{autotranslate}} just allowing an unlimited number of arguments, even named arguments.
  It's doing Magic! No arguments should be passed to {{#invoke:}}
]]

function p.autolang(frame)
    local args, pargs = cloneArgs( frame )
    if nil == args.useargs then
        if not args.base then args = pargs end
    elseif 'both' == args.useargs then
        for k,v in pairs(args) do pargs[k] = v end
        args = pargs
    elseif 'parent' == args.useargs then
        args = pargs
        if pargs.base and not args.base then
            args.base = pargs.base
        end
    end
    local base = args.base
    local userlang = frame:preprocess( '{{int:lang}}' )
    local tl, tlns = 'Template:', 10
    local tlb, fallback1, currenttemplate
    local fallback, contentlang = mw.text.split( userlang, '-', true )[1], mw.language.getContentLanguage():getCode()

    local createReturn = function(title)
        local ret
        local tlargs = {}
         -- When LUA is invoked, templates are already expanded. This must be respected.
        return frame:expandTemplate{ title = title, args = args }
    end

    if not base then
        return ("'autolang' in [[Module:Languages]] was called but the 'base' parameter could not be found." ..
            "The base parameter specifies the template that's subpages will be sought for a suitable translation.")
    end
    tlb = tl .. base .. '/'

    currenttemplate = tlb .. userlang
    local ok, exists = pcall( function()
        return mw.title.new( currenttemplate, tlns ).exists
    end )
    if ok and exists then
        return createReturn(currenttemplate)
    end

    fallback1 = frame:preprocess( '{{Fallback|1=' .. base .. '|2=' .. userlang .. '}}' )
    if fallback1 ~= contentlang then
        return createReturn(tlb .. fallback1)
    end

    currenttemplate = tlb .. fallback
    local ok, exists = pcall( function()
        return mw.title.new( currenttemplate, tlns ).exists
    end )
    if ok and exists then
        return createReturn(currenttemplate)
    end

    currenttemplate = tlb .. contentlang
    local ok, exists = pcall( function()
        return mw.title.new( currenttemplate, tlns ).exists
    end )
    if ok and exists then
        return createReturn(currenttemplate)
    end
    return createReturn(tl .. base)
end

--[=[
Usage:
{{#invoke:languages|isKnownLanguageTag|gsw}} -> 1
{{#invoke:languages|isKnownLanguageTag|doesNotExist}} ->
]=]
function p.isKnownLanguageTag(frame)
    return mw.language.isKnownLanguageTag( frame.args[1] or frame.args.tag or frame.args.code or '' ) and '1' or ''
end

function p.file_languages(frame)
    local M_link = require( 'Module:Link' )
    local contentLangInstance = mw.language.getContentLanguage()
    local pattern = frame.args.pattern or '%s (%s)'
    local original = frame.args.original or mw.title.getCurrentTitle().text
    local ext_start, _ = string.find( original, '\.%w+$' )
    local file_ext = string.sub( original, ext_start )
    original = string.sub( original, 0, ext_start-1 )
    return frame:preprocess('<gallery>\n'..(table.concat(M_link.forEachLink( p.forEachLanguage( { args= { pattern = '[[$lc]]' } } ),
        function(linkInfo)
            local filename = mw.ustring.format( pattern, original, linkInfo.text ) .. file_ext
            local ok, exists = pcall( function()
                return mw.title.new( filename, 6 ).exists
            end )
            if ok and exists then
                return mw.ustring.format( '%s|%s', filename, contentLangInstance:ucfirst( mw.language.fetchLanguageName( linkInfo.text ) ) )
            else
                return nil
            end
        end
    ), '\n'))..'\n</gallery>')
end

function p.runTests()
    return p.langLinksNonExpensive({ args= { page='Module:Languages/testcases/test' }, getParent=function() end }) == "[[Module:Languages/testcases/test/de|Deutsch]]&nbsp;&#124;&#32;[[Module:Languages/testcases/test/en|English]]&nbsp;&#124;&#32;"
end

return p;