Template:LangSwitch/doc: Difference between revisions
m →Parameters: typo |
m →Parameters: typo |
||
Line 14: | Line 14: | ||
*: Commonly used languages that are used as reasonable fallbacks include major languages of the world: English (<code>en</code>), Chinese (<code>zh</code>), French (<code>fr</code>), Spanish (<code>es</code>), Arabic (<code>ar</code>), Russian (<code>ru</code>), and Indonesian (<code>id</code>); and to a lower scale, mostly as a fallback for regional languages: Hindi (<code>hi</code>), German (<code>de</code>), Portuguese (<code>pt</code>), and Dutch (<code>nl</code>). |
*: Commonly used languages that are used as reasonable fallbacks include major languages of the world: English (<code>en</code>), Chinese (<code>zh</code>), French (<code>fr</code>), Spanish (<code>es</code>), Arabic (<code>ar</code>), Russian (<code>ru</code>), and Indonesian (<code>id</code>); and to a lower scale, mostly as a fallback for regional languages: Hindi (<code>hi</code>), German (<code>de</code>), Portuguese (<code>pt</code>), and Dutch (<code>nl</code>). |
||
*: But this also includes any national language which may be a reasonable fallback for a minority/regional-only language, unless the later is used across borders, such as Catalan (<code>ca</code>) or Kurdish (<code>ku</code>) which should be defined separately. |
*: But this also includes any national language which may be a reasonable fallback for a minority/regional-only language, unless the later is used across borders, such as Catalan (<code>ca</code>) or Kurdish (<code>ku</code>) which should be defined separately. |
||
*: Usually, you don't need to provide a specific value for language variants in a different script, that are handled now by MediaWiki using |
*: Usually, you don't need to provide a specific value for language variants in a different script, that are handled now by MediaWiki using transliterators. This includes the two major variants of Chinese: simplified <code>zh-hans</code> and traditional <code>zh-hans</code>, the simplified variant being implied in the form used by the simpler recommended code <code>zh</code>); the traditional variant needs to be specified only if the default transliterator does not reliably convert some characters. |
||
* <tt>default=<code>''language-code''</code></tt> (optional) — allows to specify which language to use when reasonable fallbacks have failed. If its value matches a given item defined in the switch, the value mapped to this item will be returned when no other languages in the switch match; if the default is not specified, or does not match any item in the switch, the value mapped to English (the default language of this wiki) will be returned. |
* <tt>default=<code>''language-code''</code></tt> (optional) — allows to specify which language to use when reasonable fallbacks have failed. If its value matches a given item defined in the switch, the value mapped to this item will be returned when no other languages in the switch match; if the default is not specified, or does not match any item in the switch, the value mapped to English (the default language of this wiki) will be returned. |
||
*: So the switch does not necessarily have to define an English message, but it should contain at least: |
*: So the switch does not necessarily have to define an English message, but it should contain at least: |
Latest revision as of 18:36, 14 May 2016
Usage
Returns a value depending on a given language, using reasonable fallbacks if the contents of the switch does not directly map a value for that language.
The given language to test, if it's not specified, is the user interface language of the viewing user.
The language of the mapped value to return when there's no match in the switch for the given language (or one of its fallbacks), is English (en) unless another default language is specified (which will be tried after standard fallbacks but before English).
Parameters
- uselang=
language-code
(optional) — the switch by default will return a value according to the viewing user, this parameter allows changing this behavior. language-code
=“Mapped value inlanguage-code
” — maps the language to a value.- Defining this parameter for a language that is used as a reasonable fallback for one or several other languages means that you won't need to define additional parameters to map these other languages, when that value is already accurate for these other languages.
- Commonly used languages that are used as reasonable fallbacks include major languages of the world: English (
en
), Chinese (zh
), French (fr
), Spanish (es
), Arabic (ar
), Russian (ru
), and Indonesian (id
); and to a lower scale, mostly as a fallback for regional languages: Hindi (hi
), German (de
), Portuguese (pt
), and Dutch (nl
). - But this also includes any national language which may be a reasonable fallback for a minority/regional-only language, unless the later is used across borders, such as Catalan (
ca
) or Kurdish (ku
) which should be defined separately. - Usually, you don't need to provide a specific value for language variants in a different script, that are handled now by MediaWiki using built-in transliterators. This includes the two major variants of Chinese: simplified
zh-hans
and traditionalzh-hans
, the simplified variant being implied in the form used by the simpler recommended codezh
); the traditional variant needs to be specified only if the default transliterator does not reliably convert some characters.
- default=
language-code
(optional) — allows to specify which language to use when reasonable fallbacks have failed. If its value matches a given item defined in the switch, the value mapped to this item will be returned when no other languages in the switch match; if the default is not specified, or does not match any item in the switch, the value mapped to English (the default language of this wiki) will be returned.- So the switch does not necessarily have to define an English message, but it should contain at least:
language-code
=“Mapped value inlanguage-code
”, if default=language-code
is present,- or en=“Mapped value in English”, when there's no specified default.
- Specifying another default language (and mapping a value specifically for it) does not prohibit mapping an additional specific value for English, but English will no longer be the last fallback.
- Note that the
language-code
indicated here may be arbitrary and can be a pseudo-language to specify a different value, even if it displays a message in English (or in any language).
- So the switch does not necessarily have to define an English message, but it should contain at least:
Supported language codes
Language codes do not necessarily have to one of those used in a separate edition of a Wikimedia project (such as Wikipedia or Wiktionary), it could be a language supported only on a multilingual site in a single edition, such as Incubator, Commons, MediaWiki or Meta.
But in all cases, the language codes used must be one of the language codes supported by MediaWiki for its localisation (otherwise they could be ignored in parameters of LangSwitch).
Language codes are normally insensitive to letter case, but this template will not recognize language codes specified using any uppercase letter.
Ideally those languages codes should be those recommended by the BCP 47 standard (essentially based on ISO 639, but with some restrictions, and many additions for supporting variants in different scripts, regions, orthographies, or locale conventions). So don't use the longer 3-letter language codes of ISO 639-3 if there's a 2-letter code from ISO-639-1. And don't use the 3-letter language family codes (from ISO 639-5).
The template also supports (for compatibility and to allow smooth migrations) some legacy codes used in Wikimedia projects, but that are no longer recommended (and may be blocked now for new translations in the Special:Translate page), such as the two major Chinese variants, or the old code for the Taraskeviza orthographic variant of Belorussian.
Examples
- Switch according to the language of the viewing user (currently for you, uselang=en)
-
- '''{{LangSwitch |ar=AR|de=DE|es=ES|en=EN|fr=FR|nl=NL|pt=PT|ru=RU|tr=TR|zh=ZH}}''' gives EN
- '''{{LangSwitch|default=gd |gd=GD|glk=GLK|other=''edit''}}''' gives GD
- '''{{LangSwitch|default=other |gd=GD|glk=GLK|other=''edit''}}''' gives edit
- '''{{LangSwitch|default=n/a |gd=GD|glk=GLK|other=''edit''}}''' gives {{{en}}}
- '''{{LangSwitch|default= |gd=GD|glk=GLK|other=''edit''}}''' gives {{{en}}}
- Switch according to the language of the content of the current page (in this page, it is Template:Pagelang)
-
- '''{{LangSwitch|uselang={{pagelang}} |ar=AR|de=DE|es=ES|en=EN|fr=FR|nl=NL|pt=PT|ru=RU|tr=TR|zh=ZH}}''' gives EN
- '''{{LangSwitch|uselang={{pagelang}}|default=gd |gd=GD|glk=GLK|other=EN [translate this]}}''' gives GD
- '''{{LangSwitch|uselang={{pagelang}}|default=other |gd=GD|glk=GLK|other=EN [translate this]}}''' gives EN [translate this]
- '''{{LangSwitch|uselang={{pagelang}}|default=n/a |gd=GD|glk=GLK|other=EN [translate this]}}''' gives {{{en}}}
- '''{{LangSwitch|uselang={{pagelang}}|default= |gd=GD|glk=GLK|other=EN [translate this]}}''' gives {{{en}}}
- Switch according to the language of a specific language
-
- '''{{LangSwitch|uselang=gsw |ar=AR|de=DE|es=ES|en=EN|fr=FR|nl=NL|pt=PT|ru=RU|tr=TR|zh=ZH}}''' gives FR — (note the fallback)
- '''{{LangSwitch|uselang=gsw-fr |ar=AR|de=DE|es=ES|en=EN|fr=FR|nl=NL|pt=PT|ru=RU|tr=TR|zh=ZH}}''' gives FR — (note the different fallback)
- '''{{LangSwitch|uselang=gsw-ch |ar=AR|de=DE|es=ES|en=EN|fr=FR|nl=NL|pt=PT|ru=RU|tr=TR|zh=ZH}}''' gives DE — (note the different fallback)
- '''{{LangSwitch|uselang=gsw-de |ar=AR|de=DE|es=ES|en=EN|gsw-ch=GSW-CH|fr=FR|nl=NL|pt=PT|ru=RU|tr=TR|zh=ZH}}''' gives GSW-CH — (note the different fallback)
- '''{{LangSwitch|uselang=gsw|default=gd |gd=GD|glk=GLK|other=EN [translate this]}}''' gives GD
- '''{{LangSwitch|uselang=gsw|default=other |gd=GD|glk=GLK|other=EN [translate this]}}''' gives EN [translate this]
- '''{{LangSwitch|uselang=gsw|default=n/a |gd=GD|glk=GLK|other=EN [translate this]}}''' gives {{{en}}}
- '''{{LangSwitch|uselang=gsw|default= |gd=GD|glk=GLK|other=EN [translate this]}}''' gives {{{en}}}