Template:LangSwitch/doc: Difference between revisions

From Test Wiki
Jump to navigation Jump to search
Content deleted Content added
duplicate argument
m 1 revision imported
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{Documentation subpage}}
{{Lua|Module:LangSwitch}}
{{Lua|Module:Fallback}}
{{Used in system}}
{{TemplateBox
|name=LangSwitch{{{sandbox|}}}


== Usage ==
|desc-de=Bietet eine Methode zur Anzeige einer Textzeichenfolge, die aus einer Auswahl von Übersetzungen in verschiedenen Sprachen ausgewählt wurde, in der Sprache, die in den Benutzereinstellungen des Benutzers/in festgelegt ist, oder in der am besten geeigneten Ausweichsprache.
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.
|desc-en=Provides a method to present a string of text selected from an array of many language translations in the language set in the user's preferences or the most appropriate fallback language.
|desc-fr=Permet de présenter un texte dans la langue de l’utilisateur, en sélectionnant depuis un ensemble de versions en différentes langues. La langue choisie est soit celle définie dans les préférences de l’utilisateur, soit la plus appropriée (déterminée par GetFallback).
|desc-ja=翻訳されている多くの言語の中から、適切な言語でテキスト文字を表示する機能を提供します。その適切な言語とは、ユーザの好みに応じて言語セットで選択された言語、あるいは、(GetFallbackで定義される)自動システムで一番最適と思われる言語です。
|desc-mk=Од разните постоечки преводи, го дава преводот на јазикот одбран во нагодувањата, или пак најсоодветниот резервен јазик (според утврденото во GetFallback).
|desc-zh=从已翻译的多语言文本组中输出以特定语言的文本。显示语言为用户设置语言,或是由GetFallback定义的后备语言。


The given language to test, if it's not specified, is the user interface language of the viewing user.
|1=en
|1label=English
|1label-de=Englisch
|1d-de=Text in englischer Sprache. Sofern nicht die Option „default=” verwendet wird, wird dieser Text standardmäßig auch dann zurückgegeben, wenn keine der angegebenen Sprachen mit der in der optionalen Option „lang=” Auswahl übereinstimmt (oder mit der in den Benutzereinstellungen ausgewählten Sprache, wenn diese Option nicht angegeben ist). Wenn Sie keinen Text anzeigen möchten, wenn die Sprache des Benutzers Englisch ist, verwenden Sie „en=~”.
|1d-en=Text in the English language. Unless the “default=” option is used, this text will also be returned by default if none of the languages provided match the language selected in the optional “lang=” option (or the language selected in the user's preferences, if that last option is not specified). If you do not want to show any text when the user's language is English, then use “en=~”.
|1d-fr=Le texte en anglais. À moins que l’option « default= » soit utilisée, ce texte sera également retournée si aucune des langues fournies ne correspond à la langue sélectionnée dans l’option facultative « lang= » (ou à la langue sélectionnée dans les préférences de l’utilisateur, si cette dernière option n’est pas indiquée). Si vous ne souhaitez retourner aucun texte lorsque la langue sélectionnée est l’anglais, utilisez « en=~ ».
|1d-ja=英語言語の文字。下記の“デフォルト”オプションを設定していない場合で、ユーザが選択した言語セットに該当する翻訳がない場合、この英語テキストが通常使われます。もしユーザの使用言語が英語で何も文字を表示させたくない場合、「en=~」と記述してください。「en」オプションのないLangSwitchテンプレートはカテゴリCategory:LangSwitch template without default versionに自動的に追加されます。
|1d-zh=英文文本。除非通过“default”设置默认显示语言,否则将在用户偏好语言的翻译文本缺失的情况下显示英文文本。如果不想在用户使用英语时显示任何文本,请指定“en=~”。
|1stat=required
|1type=string


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).
|2=xx
|2label=Translation
|2label-de=Übersetzung
|2d-de=Text übersetzt in die Sprache mit dem Code „xx“ (der Parametername „xx“ kann jeder unterstützter Sprachcode sein, der den Standards BCP 47 oder ISO 639-1 entspricht). Verwende „xx=~“, wenn du keinen Text (auch nicht den Standardtext) in dieser bestimmten Sprache haben möchtest. Du kannst auch mehrere Sprachen demselben Text zuordnen, indem du „<nowiki>{{LangSwitch |xx/yy/zz=text }}</nowiki>“ verwendest, was „<nowiki>{{LangSwitch |xx=text |yy=text |zz=text }}</nowiki>“ entspricht. Du kannst für jede übersetzte Sprache so viele Parameter wie nötig angeben.
|2d-en=Text translated in language with code “xx” (the parameter name “xx” can be any supported language code, conforming to the BCP 47 or ISO 639-1 standards). Use “xx=~” if you do not want any text (not even the default text) in this specific language. You may also map multiple languages to the same text by using “<nowiki>{{LangSwitch |xx/yy/zz=text }}</nowiki>”, which is equivalent to “<nowiki>{{LangSwitch |xx=text |yy=text |zz=text }}</nowiki>”. You can specify as many such parameters as needed for each translated language.
|2d-fr=Le texte traduit dans la langue de code « xx » (le nom du paramètre « xx » peut être n’importe quel code langue pris en charge, conforme au standard BCP 47 ou à la norme ISO 639-1). Utilisez « xx=~ » si vous ne voulez aucun texte (ni même le texte par défaut) dans cette langue spécifique. Vous pouvez également faire correspondre plusieurs langues au même texte en utilisant « <nowiki>{{LangSwitch |xx/yy/zz=texte }}</nowiki> », ce qui est équivalent à « <nowiki>{{LangSwitch |xx=texte |yy=texte |zz=texte }}</nowiki> » . Vous pouvez indiquer autant de paramètres similaires que nécessaire pour chaque langue de traduction.
|2d-ja=言語「xx」で翻訳された文字。 (パラメーター名「xx」は(BCP 47/ISO 639-1)なら何でも大丈夫で、翻訳する言語ごとにいくつでも指定可能です) もし特定の言語でメッセージを表示させたくない場合(あるいはデフォルト値として)、「xx=~」と記述してください。
|2d-mk=Текст на јазикот “xx”. “xx” може да бидат било кои поддржани јазици (BCP 47/ISO 639-1).
|2d-zh=“xx”语言的翻译文本,参数名“xx”可以是任何来自BCP 47或ISO 639-1的语言代码,可根据需要增加可能多的翻译语言。如果希望在某种特定语言中不显示任何信息(故意留空),请使用“xx=~”。可以使用“<nowiki>{{LangSwitch |xx/yy/zz=text }}</nowiki>”在多种语言中使用一个文本中,相当于“<nowiki>{{LangSwitch |xx=text |yy=text |zz=text }}</nowiki>”。
|2stat=optional
|2type=string


== Parameters ==
|3=default
* <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.
|3label=Default fallback
* <span style="font-family: monospace;"><code>''language-code''</code>=''“Mapped value in <code>language-code</code>”''</span> — maps the language to a value.
|3label-de=Standard-Fallback
*: 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.
|3d-de=Standardtext, der angezeigt wird, wenn keine der mit den Optionen „xx=text“ angegebenen Sprachen mit der über die Option „lang=” ausgewählten Sprache übereinstimmt (oder mit der in den Präferenzen des Benutzers/in ausgewählten Sprache, wenn diese Option nicht angegeben ist); standardmäßig wird die englische Version (sofern im Parameter „en=text“ angegeben) angezeigt, andernfalls wird eine Fehlermeldung ausgegeben.
*: 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>).
|3d-en=Default text to return in case none of the languages specified with the “xx=text” options match the language selected by the “lang=” option (or the language selected in user's preferences, if that option is not specified); by default, the English version (if provided in the “en=text” parameter) will be shown, otherwise a error message will be returned.
*: 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.
|3d-fr=Le texte par défaut à retourner au cas où aucune des langues indiquées par les options « xx=texte » ne correspond à la langue sélectionnée par l’option « lang= » (ou la langue sélectionnée dans les préférences de l’utilisateur, si cette option n’est pas indiquée) ; par défaut, la version anglaise (si elle est fournie dans le paramètre « en=texte ») sera affichée, sinon un message d’erreur sera retourné.
*: 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.
|3d-ja=デフォルト言語の文字。上記の「xx」言語の中にユーザが指定した言語が含まれていない場合に、このデフォルト・オプションを使います。通常はデフォルトとして英語(en)で表示されます。
* <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.
|3def=<nowiki>{{{en|}}}</nowiki> (English version)
*: So the switch does not necessarily have to define an English message, but it should contain at least:
|3stat=suggested
*:* <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,
|3type=string
*:* 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 ==
|4=lang
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.
|4label=Language code
|4label-de=Sprachcode
|4d={{Language-code-documentation}} Note that specifying “<nowiki>{{#if: {{{lang|}}} | {{{lang|}}} | {{Int:Lang}} }}</nowiki>” in this value is usually not necessary, unless one wants to override the default target language.
|4d-de={{Language-code-documentation}} Beachte, dass die Angabe von „<nowiki>{{#if: {{{lang|}}} | {{{lang|}}} | {{Int:Lang}} }}</nowiki>” in diesem Wert normalerweise nicht nötig ist, es sei denn, man will die Standardzielsprache überschreiben.
|4def-de=Wert von „<nowiki>{{Int:Lang}}</nowiki>“ (die bevorzugte Sprache von dir, der die Seite anschaut).
|4def-en=Value of “<nowiki>{{Int:Lang}}</nowiki>” (the preferred language of the visitor viewing the page).
|4def-fr=La valeur de « <nowiki>{{Int:Lang}}</nowiki> » (la langue préférée du visiteur visualisant la page).
|4def-ja=“<nowiki>{{Int:Lang}}</nowiki>”の値 (ページを閲覧しているビジターの使用言語)。
|4stat=optional-
|4type=string


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).
|5=nocat
|5label=No category?
|5label-de=Keine Kategorie?
|5d-de=“nocat=1” überschreibt das Standardverhalten, das (auf der Kategorie-Seite „LangSwitch-Vorlage ohne Standardversion“) die falschen Verwendungen dieser Vorlage verfolgt, wenn keine der beiden Optionen „en=Text auf Englisch“ oder „default=Text standardmäßig“ mit einem nicht leeren Wert angegeben ist.
|5d-en=“nocat=1” will overwrite the default behavior which tracks (in the “LangSwitch template without default version” category page) the incorrect uses of this template, where none of the two options “en=text in English” or “default=text by default” is specified with a non-empty value.
|5d-fr=« nocat=1 » permet d’empêcher le comportement par défaut qui trace (dans la page de catégorie « LangSwitch template without default version ») les usages incorrects de modèle, où aucune des deux options « en=texte en anglais » ou « default=texte par défaut » n’est spécifiée avec une valeur non vide.
|5d-ja=言語オプションに「en」や「default」オプションがないページには自動的にカテゴリCategory:LangSwitch template without default versionに追加され、「nocat=1」はデフォルト動作を上書きします。
|5stat=optional-
|5type=string


Language codes are normally insensitive to letter case, but this template will not recognize language codes specified using any uppercase letter.
|example=
|usage-notes={{LangSwitch
|de='''Warning:''' Diese Vorlage '''SOLLTE NICHT''' außerhalb von Software-Interface verwendet werden. Sie '''SOLLTE'' zum Beispiel '''NICHT''' dazu benutzt werden, mehrsprachige Beschreibungen von Medien, Kategorien oder so weiter zu verwalten.
|en='''Warning:''' This template '''SHOULD NOT''' be used out of software interface purpose. For example it '''SHOULD NOT''' be used to manage multilingual description of the subject of a media or a category or whatsoever.
|fr='''Attention:''' Ce modèle '''NE DEVRAIT PAS''' être utilisé en dehors de la traduction de l'interface logicielle. Par exemple il ne '''DEVRAIT PAS''' être utilisé pour gérer les descriptions multilingues du sujet d'un média ou d'une catégorie.
}}


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).
|seealso=
* {{Tl|Autotranslate}} for template internationalization (i18n) mechanism for templates that use ''named'' parameters
* {{Tl|Fallback}} and {{Tl|SuperFallback}}, based on {{Tl|GetFallback}} and {{Tl|GetFallback2}})
* {{Tl|Multilingual link}}
* [[:Category:Internationalization templates using LangSwitch]]
* {{Tl|Multilingual description}}, not using LangSwitch or any fallbacks, but generating vertical lists of translated texts or arbitrary length (without any English or default language requirement) in separate paragraphs; the rendered list is collapsible by a language selection menu at top of the rendered page (it is collapsed by default to show only the user's preferred or selected language, if it matches exactly).
* {{Tl|Translation table}}, not using LangSwitch or any fallbacks, but generating horizontal lists of translations (without any English or default language requirement); the rendered list is statically displaying ''all'' the provided languages, and this template is intended for translating just one term or short expression (otherwise the previous template should be used).


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.
|setscats=[[:Category:Internationalization templates using LangSwitch]]
|type=
|namespace=
|usergroup=all
|i18n-method=-
|i18n-desc={{I18n templates}}
|print=multi
|relieson=[[Module:LangSwitch]]
|useTemplateData=only
}}


== Examples ==
== Examples ==
; Switch according to the language of the viewing user (currently for you, <span style="font-family: monospace;">lang={{uselang}}</span>) :
:* <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 ==
=== Without a default option ===
{{TemplateData header}}
Here are a few examples showing template behavior for three languages: English, Italian and Corsican (which defaults to Italian if Corsican text is not available):
<templatedata>

{
{|class="wikitable"
"params": {
|-
"lang": {
!scope="col"| Test
"label": {
!scope="col"| Code
"en": "Language code",
!scope="col"| lang=en
"pt": "Código do idioma",
!scope="col"| lang=it
"pt-br": "Código de idioma"
!scope="col"| lang=co
},
|-
"description": {
| No en; default
"en": "The ISO 639 language code.",
| {{Tlx|LangSwitch{{{sandbox|}}}|it{{=}}Italian|default{{=}}default}}
"pt": "O código do idioma ISO 639.",
| {{LangSwitch{{{sandbox|}}}|it=Italian|default=default|lang=en}}
"pt-br": "O código de idioma ISO 639."
| {{LangSwitch{{{sandbox|}}}|it=Italian|default=default|lang=it}}
},
| {{LangSwitch{{{sandbox|}}}|it=Italian|default=default|lang=co}}
"default": "{{int:lang}}",
|-
"type": "string"
| No en; no default
},
| {{Tlx|LangSwitch{{{sandbox|}}}|it{{=}}Italian|co{{=}}Corsu}}
"default": {
| {{LangSwitch{{{sandbox|}}}|it=Italian|co=Corsu|lang=en|nocat=1}}<ref name="c">would add [[:Category:LangSwitch template without default version]]</ref>
"label": {
| {{LangSwitch{{{sandbox|}}}|it=Italian|co=Corsu|lang=it|nocat=1}}<ref name="c"/>
"en": "Default fallback",
| {{LangSwitch{{{sandbox|}}}|it=Italian|co=Corsu|lang=co|nocat=1}}<ref name="c"/>
"pt": "Recuperação predefinida",
|-
"pt-br": "Fallback padrão"
| en; default
},
| {{Tlx|LangSwitch{{{sandbox|}}}|en{{=}}English|co{{=}}Corsu|default{{=}}default}}
"description": {
| {{LangSwitch{{{sandbox|}}}|en=English|co=Corsu|default=default|lang=en}}
"en": "The default fallback result, used when the language is not provided.",
| {{LangSwitch{{{sandbox|}}}|en=English|co=Corsu|default=default|lang=it}}
"pt": "O resultado da recuperação predefinida, utilizado quando não é fornecido o idioma",
| {{LangSwitch{{{sandbox|}}}|en=English|co=Corsu|default=default|lang=co}}
"pt-br": "O resultado de fallback padrão, usado quando o idioma não é fornecido."
|-
},
| en; no default
"suggested": true,
| {{Tlx|LangSwitch{{{sandbox|}}}|en{{=}}English|co{{=}}Corsu}}
"type": "content"
| {{LangSwitch{{{sandbox|}}}|en=English|co=Corsu|lang=en}}
},
| {{LangSwitch{{{sandbox|}}}|en=English|co=Corsu|lang=it}}
"en": {
| {{LangSwitch{{{sandbox|}}}|en=English|co=Corsu|lang=co}}
"label": {
|-
"en": "English",
| en; skip default
"pt": "Inglês",
| {{Tlx|LangSwitch{{{sandbox|}}}|en{{=}}English|co{{=}}Corsu|default{{=}}~}}
"pt-br": "Inglês"
| {{LangSwitch{{{sandbox|}}}|en=English|co=Corsu|default=~|lang=en}}
},
| {{LangSwitch{{{sandbox|}}}|en=English|co=Corsu|default=~|lang=it}}
"description": {
| {{LangSwitch{{{sandbox|}}}|en=English|co=Corsu|default=~|lang=co}}
"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.",
| en; empty default
"pt-br": "Usado quando o idioma é inglês ou se `default` e o idioma não forem fornecidos."
| {{Tlx|LangSwitch{{{sandbox|}}}|en{{=}}English|co{{=}}Corsu|default{{=}}}}
},
| {{LangSwitch{{{sandbox|}}}|en=English|co=Corsu|default=|lang=en}}
"suggested": true,
| {{LangSwitch{{{sandbox|}}}|en=English|co=Corsu|default=|lang=it}}
"type": "content"
| {{LangSwitch{{{sandbox|}}}|en=English|co=Corsu|default=|lang=co}}
}
|-
}
| Skip en; default
}
| {{Tlx|LangSwitch{{{sandbox|}}}|en{{=}}~|it{{=}}Italian|default{{=}}default}}
</templatedata>
| {{LangSwitch{{{sandbox|}}}|en=~|it=Italian|default=default|lang=en}}
<includeonly>{{Sandbox other||
| {{LangSwitch{{{sandbox|}}}|en=~|it=Italian|default=default|lang=it}}
<!-- template categories and interwiki links -->
| {{LangSwitch{{{sandbox|}}}|en=~|it=Italian|default=default|lang=co}}
[[Category:Translation templates|LangSwitch]]
|-
[[Category:User interface language dependent templates|LangSwitch]]<!-- only if there's no lang parameter -->
| Skip en; no default
}}</includeonly>
| {{Tlx|LangSwitch{{{sandbox|}}}|en{{=}}~|it{{=}}Italian}}
| {{LangSwitch{{{sandbox|}}}|en=~|it=Italian|lang=en}}
| {{LangSwitch{{{sandbox|}}}|en=~|it=Italian|lang=it}}
| {{LangSwitch{{{sandbox|}}}|en=~|it=Italian|lang=co}}
|-
| Empty en; no default
| {{Tlx|LangSwitch{{{sandbox|}}}|en{{=}}|it{{=}}Italian}}
| {{LangSwitch{{{sandbox|}}}|en=|it=Italian|lang=en}}<ref name="c"/>
| {{LangSwitch{{{sandbox|}}}|en=|it=Italian|lang=it}}
| {{LangSwitch{{{sandbox|}}}|en=|it=Italian|lang=co}}<ref name="c"/>
|-
| en; default; skip it
| {{Tlx|LangSwitch{{{sandbox|}}}|en{{=}}English|it{{=}}~|co{{=}}Corsu|default{{=}}default}}
| {{LangSwitch{{{sandbox|}}}|en=English|it=~|co=Corsu|default=default|lang=en}}
| {{LangSwitch{{{sandbox|}}}|en=English|it=~|co=Corsu|default=default|lang=it}}
| {{LangSwitch{{{sandbox|}}}|en=English|it=~|co=Corsu|default=default|lang=co}}
|-
| en; default; empty it
| {{Tlx|LangSwitch{{{sandbox|}}}|en{{=}}English|it{{=}}|co{{=}}Corsu|default{{=}}default}}
| {{LangSwitch{{{sandbox|}}}|en=English|it=|co=Corsu|default=default|lang=en}}
| {{LangSwitch{{{sandbox|}}}|en=English|it=|co=Corsu|default=default|lang=it}}
| {{LangSwitch{{{sandbox|}}}|en=English|it=|co=Corsu|default=default|lang=co}}
|-
| en; no default; skip it
| {{Tlx|LangSwitch{{{sandbox|}}}|en{{=}}English|it{{=}}~|co{{=}}Corsu}}
| {{LangSwitch{{{sandbox|}}}|en=English|it=~|co=Corsu|lang=en}}
| {{LangSwitch{{{sandbox|}}}|en=English|it=~|co=Corsu|lang=it}}
| {{LangSwitch{{{sandbox|}}}|en=English|it=~|co=Corsu|lang=co}}
|-
| Forced "lang=co"
| {{Tlx|LangSwitch{{{sandbox|}}}|en{{=}}English|co{{=}}Corsu|default{{=}}default|lang{{=}}co}}
| {{LangSwitch{{{sandbox|}}}|en=English|co=Corsu|default=default|lang=co}}
| {{LangSwitch{{{sandbox|}}}|en=English|co=Corsu|default=default|lang=co}}
| {{LangSwitch{{{sandbox|}}}|en=English|co=Corsu|default=default|lang=co}}
|}

{{LangSwitch
|en=<nowiki />
=== Default option ===
The default option is intended for providing more language independent option. For example:
|de=<nowiki />
=== Standardoption ===
Die Standardoption ist dafür gedacht, mehr sprachunabhängige Optionen zu bieten. Zum Beispiel:}}
<syntaxhighlight lang="wikitext" copy>
{{LangSwitch{{{sandbox|}}}
|de={{Wd|Warschau}}
|en={{W|Warsaw}}
|fr={{Wf|Varsovie}}
|ja={{W日|ワルシャワ}}
|pl={{WP|Warszawa}}
|ru={{Wr|Варшава}}
|default=[[d:Q270]]
}}
</syntaxhighlight>
{{LangSwitch
|en=provides a link to Wikipedia articles in case one of the languages provided matches user's language but will link to Commons gallery page ([[Warsaw]]) if any other language is used.

The expression <code><nowiki>{{W|Q270||d}}</nowiki></code> is equivalent to the shorter <code><nowiki>[[d:Q270]]</nowiki></code> (it just does not show the “d:”).
|de=bietet einen Link zu Wikipedia-Artikeln, falls eine der angebotenen Sprachen mit der Sprache des Benutzers übereinstimmt, verlinkt aber auf die Commons-Galerie-Seite ([[Warsaw]]), wenn eine andere Sprache verwendet wird.

Der Ausdruck <code><nowiki>{{W|Q270||d}}</nowiki></code> ist gleichbedeutend mit dem kürzeren <code><nowiki>[[d:Q270]]</nowiki></code> (nur das „d:” wird nicht angezeigt).
}}

=== Combination of multiple languages in the same option ===
“<code><nowiki>{{LangSwitch |de=Grün |es/it/pt=Verde |fr=Vert |en=Green |lang={{{lang|{{int:lang}}}}} }}</nowiki></code>” gives “{{LangSwitch |de=Grün |es/it/pt=Verde |fr=Vert |en=Green |lang={{{lang|{{int:lang}}}}} }}” for the language with code <kbd>{{{lang|{{int:lang}}}}}</kbd>.

Note that several language codes (separated by <code>/</code>) are combined in the same parameter name, when these languages are mapped to the same output text (this helps simplifying usages).

However this combination still does not work correctly for the language code <code>en</code> if there’s no parameter <code>default=</code> or <code>en=</code> specified separately (when this occurs, this template still returns a usage error message<ref name="c"/>).

=== Returning empty texts ===
* “<code><nowiki>red{{LangSwitch |en=~ |default=&amp;#32;({{I18n/red}}) }}</nowiki></code>”,
* “<code><nowiki>bleu{{LangSwitch |fr=~ |default=&amp;#32;({{I18n/blue}}) }}</nowiki></code>”, and
* “<code><nowiki>orange{{LangSwitch |en/fr=~ |default=&amp;#32;({{I18n/orange}}) }}</nowiki></code>”
are respectively and conditionally appending parenthesized translations of
* the standard English term “red” in (when the current user language is ''not'' standard English, or simple English, or any language where standard English is a predefined fallback),
* the standard French term “bleu” (when the current user language is ''not'' standard French, or Cajun French, or any language where standard French is a predefined fallback), and
* the standard English or French term “orange” (when the current user language is ''not'' standard French or English, or any language where standard French or English is a predefined fallback):

{|class="wikitable"
|-
|style="background:#A00;color:#FFF"| red{{LangSwitch |en=~ |default=&#32;({{I18n/red}}) }}
|style="background:#00A;color:#FFF"| bleu{{LangSwitch |fr=~ |default=&#32;({{I18n/blue}}) }}
|style="background:#FA0;color:#FFF"| orange{{LangSwitch |fr=~ |default=&#32;({{I18n/blue}}) }}
|}


== Notes ==
<references/>
<includeonly>
[[Category:Internationalization templates]]
</includeonly>

Latest revision as of 05:25, 22 February 2026

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

[edit source]
  • lang=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 in language-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 builtin transliterators. This includes the two major variants of Chinese: simplified zh-hans and traditional zh-hant, the simplified variant being implied in the form used by the simpler recommended code zh); 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 in language-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).

Supported language codes

[edit source]

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 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).

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.

Examples

[edit source]
Switch according to the language of the viewing user (currently for you, lang=en)
  • '''{{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}}''' gives EN
  • '''{{LangSwitch|default=''edit''|en=EN|gd=GD|glk=GLK}}''' gives EN
  • '''{{LangSwitch|default=''edit''|gd=GD|glk=GLK}}''' gives edit
Switch according to the language of the content of the current page (in this page, it is en)
  • '''{{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}}''' gives EN
  • '''{{LangSwitch|lang={{CURRENTCONTENTLANGUAGE}}|default=''edit''|en=EN|gd=GD|glk=GLK}}''' gives EN
  • '''{{LangSwitch|lang={{CURRENTCONTENTLANGUAGE}}|default=''edit''|gd=GD|glk=GLK}}''' gives edit
Switch according to the language of a specific language
  • '''{{LangSwitch|lang=gsw|default=[translate this]|it=IT}}''' gives [translate this]
  • '''{{LangSwitch|lang=gsw|default=[translate this]|it=IT|en=EN}}''' gives EN
  • '''{{LangSwitch|lang=gsw|default=[translate this]|it=IT|en=EN|fr=FR}}''' gives EN
  • '''{{LangSwitch|lang=gsw|default=[translate this]|it=IT|en=EN|de=DE}}''' gives DE
  • '''{{LangSwitch|lang=gsw|default=[translate this]|it=IT|en=EN|de=DE|fr=FR}}''' gives DE
  • '''{{LangSwitch|lang=gsw|default=[translate this]|it=IT|en=EN|de=DE|fr=FR|gsw=GSW}}''' gives GSW

TemplateData

[edit source]
This is the TemplateData for this template used by TemplateWizard, VisualEditor and other tools. See a monthly parameter usage report for Template:LangSwitch in articles based on its TemplateData.

TemplateData for LangSwitch

<templatedata> { "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": "en", "type": "string" }, "default": { "label": { "en": "Default fallback",

               "pt": "Recuperação predefinida",

"pt-br": "Fallback padrão" }, "description": { "en": "The default fallback result, used when the language is not provided.",

               "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" } } } </templatedata>