Template:LangSwitch/doc: Difference between revisions
From Test Wiki
Content deleted Content added
Removing Julwanri_Munthe_Aku_Demokrat.jpg, it has been deleted from Commons by Krd because: No permission since 2 May 2025. |
m 1 revision imported |
||
| (5 intermediate revisions by 3 users not shown) | |||
| Line 1: | Line 1: | ||
{{Documentation subpage}} |
{{Documentation subpage}} |
||
{{Lua|Module: |
{{Lua|Module:Fallback}} |
||
<!-- PLEASE ADD CATEGORIES AT THE BOTTOM OF THIS PAGE --> |
|||
== Usage == |
|||
'''Julwanri Munthe'''== {{LangSwitch|en=How to|nl=Hoe werkt het|ja=使い方}} == |
|||
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. |
|||
{{Pre2|<nowiki>{{LangSwitch |
|||
|de = lahir di Girsang, 1 Juli 1988 |
|||
|en = tumbuh besar di Kawasan Danau Toba |
|||
|es = aktivis PMKRI |
|||
|fr = Pengurus Pusat Pemuda Katolik |
|||
|it = Pengamat Pertahanan, Keamanan dan Intelijen |
|||
|default = NASAMEN |
|||
}}</nowiki>}} |
|||
Veloz et Exactus |
|||
{{LangSwitch|en=<code>default</code> or <code>en</code> is required}} |
|||
The given language to test, if it's not specified, is the user interface language of the viewing user. |
|||
== {{Int Examples}} == |
|||
;{{LangSwitch|en=This code:|nl=Deze code:|ja=コード:}} |
|||
<span style="border: 2px dotted #81B9F9; background-color: #F0F0F0; margin:10px; padding:5px;"> |
|||
<code><nowiki>{{LangSwitch |
|||
|de = wort |
|||
|en = word |
|||
|es = palabra |
|||
|fr = mot |
|||
|it = parola |
|||
|nl = woord |
|||
|ja = 言葉 |
|||
}}</nowiki></code></span> |
|||
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 (<span style="font-family: monospace;">en</span>) unless another default language is specified (which will be tried after standard fallbacks but before English). |
|||
;{{LangSwitch|en=gives:|nl=geeft:|ja=結果}} |
|||
<span style="border: 2px dotted #81B9F9; background-color: #F0F0F0; margin:10px; padding:5px;"> |
|||
{{LangSwitch |
|||
|de = wort |
|||
|en = word |
|||
|es = palabra |
|||
|fr = mot |
|||
|it = parola |
|||
|nl = woord |
|||
|ja = 言葉 |
|||
}}</span> |
|||
== Parameters == |
|||
* <span style="font-family: monospace;">lang=<code>''language-code''</code></span> (optional) — the switch by default will return a value according to the viewing user, this parameter allows changing this behavior. |
|||
* <span style="font-family: monospace;"><code>''language-code''</code>=''“Mapped value in <code>language-code</code>”''</span> — 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 (<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. |
|||
*: Usually, you don't need to provide a specific value for language variants in a different script, that are handled now by MediaWiki using builtin transliterators. This includes the two major variants of Chinese: simplified <code>zh-hans</code> and traditional <code>zh-hant</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. |
|||
* <span style="font-family: monospace;">default=<code>''language-code''</code></span> (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: |
|||
*:* <span style="font-family: monospace;"><code>language-code</code>=''“Mapped value in <code>language-code</code>”''</span>, if <span style="font-family: monospace;">default=<code>''language-code''</code></span> is present, |
|||
*:* or <span style="font-family: monospace;">en=''“Mapped value in English”''</span>, 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 <code>''language-code''</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). |
|||
== 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). |
|||
<span style="border: 2px dotted #81B9F9; background-color: #F0F0F0; margin:10px; padding:5px;"> |
|||
<code><nowiki>{{LangSwitch |
|||
|de = wort |
|||
|en = word |
|||
|es = palabra |
|||
|fr = mot |
|||
|it = parola |
|||
|nl = woord |
|||
|ja = 言葉 |
|||
|lang = vec |
|||
}}</nowiki></code></span> |
|||
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 os 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). |
|||
<span style="border: 2px dotted #81B9F9; background-color: #F0F0F0; margin:10px; padding:5px;"> |
|||
{{LangSwitch |
|||
|de = wort |
|||
|en = word |
|||
|es = palabra |
|||
|fr = mot |
|||
|it = parola |
|||
|nl = woord |
|||
|ja = 言葉 |
|||
|lang = vec |
|||
}}</span> |
|||
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 Belarusian. |
|||
== {{Int See also}} == |
|||
== Examples == |
|||
* {{TL|Int *}} |
|||
; Switch according to the language of the viewing user (currently for you, <span style="font-family: monospace;">lang={{uselang}}</span>) : |
|||
* {{tl|TranslateThis}} |
|||
:* <span style="font-family: monospace;"><nowiki>'''{{LangSwitch|ar=AR|de=DE|en=EN|es=ES|fr=FR|it=IT|ja=JA|ko=KO|nl=NL|pt=PT|ru=RU|tr=TR|zh=ZH}}'''</nowiki></span> gives '''{{LangSwitch|ar=AR|de=DE|en=EN|es=ES|fr=FR|it=IT|ja=JA|ko=KO|nl=NL|pt=PT|ru=RU|tr=TR|zh=ZH}}''' |
|||
:* <span style="font-family: monospace;"><nowiki>'''{{LangSwitch|default=''edit''|en=EN|gd=GD|glk=GLK}}'''</nowiki></span> gives '''{{LangSwitch|default=''edit''|en=EN|gd=GD|glk=GLK}}''' |
|||
:* <span style="font-family: monospace;"><nowiki>'''{{LangSwitch|default=''edit''|gd=GD|glk=GLK}}'''</nowiki></span> gives '''{{LangSwitch|default=''edit''|gd=GD|glk=GLK}}''' |
|||
: |
|||
; Switch according to the language of the content of the current page (in this page, it is <span style="font-family: monospace;">{{CURRENTCONTENTLANGUAGE}}</span>) : |
|||
:* <span style="font-family: monospace;"><nowiki>'''{{LangSwitch|lang={{CURRENTCONTENTLANGUAGE}}|ar=AR|de=DE|en=EN|es=ES|fr=FR|it=IT|ja=JA|ko=KO|nl=NL|pt=PT|ru=RU|tr=TR|zh=ZH}}'''</nowiki></span> gives '''{{LangSwitch|lang={{CURRENTCONTENTLANGUAGE}}|ar=AR|de=DE|en=EN|es=ES|fr=FR|it=IT|ja=JA|ko=KO|nl=NL|pt=PT|ru=RU|tr=TR|zh=ZH}}''' |
|||
:* <span style="font-family: monospace;"><nowiki>'''{{LangSwitch|lang={{CURRENTCONTENTLANGUAGE}}|default=''edit''|en=EN|gd=GD|glk=GLK}}'''</nowiki></span> gives '''{{LangSwitch|lang={{CURRENTCONTENTLANGUAGE}}|default=''edit''|en=EN|gd=GD|glk=GLK}}''' |
|||
:* <span style="font-family: monospace;"><nowiki>'''{{LangSwitch|lang={{CURRENTCONTENTLANGUAGE}}|default=''edit''|gd=GD|glk=GLK}}'''</nowiki></span> gives '''{{LangSwitch|lang={{CURRENTCONTENTLANGUAGE}}|default=''edit''|gd=GD|glk=GLK}}''' |
|||
: |
|||
; Switch according to the language of a specific language : |
|||
:* <span style="font-family: monospace;"><nowiki>'''{{LangSwitch|lang=gsw|default=[translate this]|it=IT}}'''</nowiki></span> gives '''{{LangSwitch|lang=gsw|default=[translate this]|it=IT}}''' |
|||
:* <span style="font-family: monospace;"><nowiki>'''{{LangSwitch|lang=gsw|default=[translate this]|it=IT|en=EN}}'''</nowiki></span> gives '''{{LangSwitch|lang=gsw|default=[translate this]|it=IT|en=EN}}''' |
|||
:* <span style="font-family: monospace;"><nowiki>'''{{LangSwitch|lang=gsw|default=[translate this]|it=IT|en=EN|fr=FR}}'''</nowiki></span> gives '''{{LangSwitch|lang=gsw|default=[translate this]|it=IT|en=EN|fr=FR}}''' |
|||
:* <span style="font-family: monospace;"><nowiki>'''{{LangSwitch|lang=gsw|default=[translate this]|it=IT|en=EN|de=DE}}'''</nowiki></span> gives '''{{LangSwitch|lang=gsw|default=[translate this]|it=IT|en=EN|de=DE}}''' |
|||
:* <span style="font-family: monospace;"><nowiki>'''{{LangSwitch|lang=gsw|default=[translate this]|it=IT|en=EN|de=DE|fr=FR}}'''</nowiki></span> gives '''{{LangSwitch|lang=gsw|default=[translate this]|it=IT|en=EN|de=DE|fr=FR}}''' |
|||
:* <span style="font-family: monospace;"><nowiki>'''{{LangSwitch|lang=gsw|default=[translate this]|it=IT|en=EN|de=DE|fr=FR|gsw=GSW}}'''</nowiki></span> gives '''{{LangSwitch|lang=gsw|default=[translate this]|it=IT|en=EN|de=DE|fr=FR|gsw=GSW}}''' |
|||
== TemplateData == |
|||
<includeonly>[[Category:Localisation templates]]</includeonly> |
|||
{{TemplateData header}} |
|||
<templatedata> |
<templatedata> |
||
{ |
{ |
||
"params": { |
"params": { |
||
"lang": { |
|||
"label": { |
|||
"en": "Language code", |
|||
"pt": "Código do idioma", |
|||
"pt-br": "Código de idioma" |
|||
}, |
|||
"description": { |
|||
"en": "The ISO 639 language code.", |
|||
"pt": "O código do idioma ISO 639.", |
|||
"pt-br": "O código de idioma ISO 639." |
|||
}, |
|||
"default": "{{int:lang}}", |
|||
"type": "string" |
|||
}, |
|||
"default": { |
"default": { |
||
"label": { |
"label": { |
||
" |
"en": "Default fallback", |
||
"pt": "Recuperação predefinida", |
|||
"pt-br": "Fallback padrão" |
|||
}, |
}, |
||
"description": { |
"description": { |
||
"en": "The default fallback result, used when the language is not provided.", |
|||
"ja": "翻訳元となる原文を入力ししてください。原則として地の文と同じ言語の文言が原文です。特に決まっていない、原文が存在しない場合は何も書かず、代わりに英語訳を入力してください。暫定的に英語訳を原文の代わりに表示します。" |
|||
"pt": "O resultado da recuperação predefinida, utilizado quando não é fornecido o idioma", |
|||
"pt-br": "O resultado de fallback padrão, usado quando o idioma não é fornecido." |
|||
}, |
}, |
||
" |
"suggested": true, |
||
"type": "content" |
|||
}, |
|||
"en": { |
|||
"label": { |
|||
"en": "English", |
|||
"pt": "Inglês", |
|||
"pt-br": "Inglês" |
|||
}, |
|||
"description": { |
|||
"en": "Used when the language is English or if `default` and the language is not provided.", |
|||
"pt": "Utilizado quando o idioma é o inglês ou se não é fornecida a `predefinição` e o idioma.", |
|||
"pt-br": "Usado quando o idioma é inglês ou se `default` e o idioma não forem fornecidos." |
|||
}, |
}, |
||
" |
"suggested": true, |
||
" |
"type": "content" |
||
} |
} |
||
} |
} |
||
"format": "{{_\n |_ = _\n }}" |
|||
} |
} |
||
</templatedata> |
</templatedata> |
||
<includeonly>{{Sandbox other|| |
|||
<!-- template categories and interwiki links --> |
|||
[[Category:Translation templates|LangSwitch]] |
|||
[[Category:User interface language dependent templates|LangSwitch]]<!-- only if there's no lang parameter --> |
|||
}}</includeonly> |
|||