Permanently protected template

Template:Wikilangcode

From Meta, a Wikimedia project coordination wiki
Jump to navigation Jump to search

www

Template documentation[view] [edit] [history] [purge]

Usage

This template converts standard BCP47 locale tags to Wikimedia language codes, and fixes a few current violations of the BCP47 standard (for inclusion in the lang HTML attribute) by Wikimedia sites for their language codes.

It also normalizes these codes to lowercase only (though it is not mandatory).

Note: for unmapped or undetermined wiki codes, it returns "www" (which is appropriate to create links to the default pages of Wikimedia projects, where visitors can select their desired language.

Use this template only in interwiki URLs. For using it in interwiki language code prefixes in wikilinks, the default value "www" should be tested as otherwise it will create a link to a local page whose name starts by "www:" (creating most probably a "red link" to an inexistant local page).

Notes

This template is based on the code of Template:BCP47, but it reverts some codes that are still violated or not supported as Wikimedia projects (notably in Wikipedia), and maps some valid BCP47 codes to alternate codes (such as mapping codes of sign languages to codes of their associated written languages).

Examples

  • Unaffected codes (most of them, valid for use HTML/XML/CSS, are not valid interwikis), for example:
    • "{{Wikilangcode|en}}" returns: "en"
    • "{{Wikilangcode|nb}}" returns: "no" (same as "no" only where it's used by interwikis on Wikimedia sites)
    • "{{Wikilangcode|zh-hans}}" returns: "zh"
    • "{{Wikilangcode|zh-hant}}" returns: "zh"
    • "{{Wikilangcode|zh-cn}}" returns: "zh"
  • Changes preferable with BCP47 for improved interoperability (not really violations, these replacements for HTML/XML/CSS should not be used for interwikis, as long as their domain names are not aliased):
    • "{{Wikilangcode|be-x-old}}" returns: "be-x-old"
    • "{{Wikilangcode|bh}}" returns: "bh" (it's an old ISO 639-1 code for a language family, valid for BCP47 but not recommended, but Wikimedia uses it to mean only "bho" in that family, and replaces this ISO 639-1 code in HTML contents by the ISO 639-3 code)
    • "{{Wikilangcode|mo}}" returns: "ro"
    • "{{Wikilangcode|no-bok}}" returns: "no" (same as "no", only where "no" is used by interwikis on Wikimedia sites to mean only Bokmål plus Riksmål as its minor dialectal variant, but not Nynorsk as allowed in BCP47 and ISO639-1, where "no" is a macrolanguage)
    • "{{Wikilangcode|no-nyn}}" returns: "no"
    • "{{Wikilangcode|zh-cmn}}" returns: "zh" (alias of "zh" on Wikimedia sites ?)
    • "{{Wikilangcode|zh-wuu}}" returns: "wuu"
    • "{{Wikilangcode|zh-yue}}" returns: "zh-yue"
  • The following codes are not recommended (they are unnecessary aliases with preferred values) but they are still conforming to the standard and are not affected (this template still does not resolve them to their canonical codes):
    • "{{Wikilangcode|en-latn}}" returns: "en" (alias of "en"?)
    • "{{Wikilangcode|zh-cmn-hans-cn}}" returns: "zh-cmn-hans-cn" (alias of "cmn-hans-cn"? or simply "zh-hans-cn"?)
  • Changes required by BCP47 (due to standard violation), using standard codes when they exist (but these replacements for HTML/XML/CSS conformance are not valid in interwikis, as long as their domains are not aliased):
    • "{{Wikilangcode|als}}" returns: "als"
    • "{{Wikilangcode|bat-smg}}" returns: "bat-smg"
    • "{{Wikilangcode|fiu-vro}}" returns: "fiu-vro"
    • "{{Wikilangcode|roa-rup}}" returns: "roa-rup"
    • "{{Wikilangcode|simple}}" returns: "simple"
    • "{{Wikilangcode|sr-sc}}" returns: "sr-sc"
    • "{{Wikilangcode|sr-sl}}" returns: "sr-sl"
    • "{{Wikilangcode|zh-classical}}" returns: "lzh"
  • Changes required by BCP47 (due to standard violation), currently using private-use extensions:
    • "{{Wikilangcode|cbk-zam}}" returns: "cbk-zam"
    • "{{Wikilangcode|de-formal}}" returns: "de"
    • "{{Wikilangcode|eml}}" returns: "eml"
    • "{{Wikilangcode|map-bms}}" returns: "map-bms"
    • "{{Wikilangcode|nl-informal}}" returns: "nl"
    • "{{Wikilangcode|nrm}}" returns: "nrm" (note that Norman is actually an unencoded macrolanguage with three separate modern branches: one is the continental minority regional language, considered as a variant of French and called "Normand" in French, the two others are Jériais and Guernésiais, both having now local official status in Jersey and Guernsey as individual languages; none of these three modern languages, or the macrolanguage if there's one, or the historic Old Norman from which they are descending, are also encoded).
    • "{{Wikilangcode|roa-tara}}" returns: "roa-tara"
  • Invalid codes detected:
    • "{{Wikilangcode|a&b}}" returns: "www"
    • "{{Wikilangcode|'en'}}" returns: "www"
    • "{{Wikilangcode|"en"}}" returns: "www"
    • "{{Wikilangcode|a/en}}" returns: "www"
    • "{{Wikilangcode|1x}}" returns: "www"
    • "{{Wikilangcode|-aa}}" returns: "www"