Jump to content
Toggle menu
  • 8 articles
  • 75 files
  • 7 users
  • 37.8K edits
Neodyland Wiki
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Template:LangSwitch/doc: Difference between revisions

Template page
mNo edit summary
mNo edit summary
Line 5: Line 5:


|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-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-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-ja=翻訳されている多くの言語の中から、適切な言語でテキスト文字を表示する機能を提供します。その適切な言語とは、ユーザの好みに応じて言語セットで選択された言語、あるいは、(GetFallbackで定義される)自動システムで一番最適と思われる言語です。
|desc-mk=Од разните постоечки преводи, го дава преводот на јазикот одбран во нагодувањата, или пак најсоодветниот резервен јазик (според утврденото во GetFallback).
|desc-mk=Од разните постоечки преводи, го дава преводот на јазикот одбран во нагодувањата, или пак најсоодветниот резервен јазик (според утврденото во GetFallback).
Line 11: Line 11:


|1=en
|1=en
| 1label = English
|1label=English
|1d-en=Text in English language. Unless ''default'' option is used, this text will also be used if the languages provided do not include the language set in the user's preferences. If you do not want to show any text when the user's language is English, then use "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-ja=英語言語の文字。下記の''デフォルト''オプションを設定していない場合で、ユーザが選択した言語セットに該当する翻訳がない場合、この英語テキストが通常使われます。もしユーザの使用言語が英語で何も文字を表示させたくない場合、「en=~」と記述してください。「en」オプションのないLangSwitchテンプレートはカテゴリCategory:LangSwitch template without default versionに自動的に追加されます。
|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=~”。
|1d-zh=英文文本。除非通过“default”设置默认显示语言,否则将在用户偏好语言的翻译文本缺失的情况下显示英文文本。如果不想在用户使用英语时显示任何文本,请指定“en=~”。
|1stat=required
|1stat=required
Line 19: Line 20:


|2=xx
|2=xx
|2d-en=Translated text in language ''xx'' (the parameter name ''xx'' can be any supported language code (from BCP 47/ISO 639-1), and you can specify as many such parameters as needed for each translated language). Use "xx=~" if you do not want any message (or default) in some specific language. You can map multiple languages to a single text by using "<nowiki>{{LangSwitch|xx/yy/zz=text}}</nowiki>" which is equivalent to "<nowiki>{{LangSwitch|xx=text|yy=text|zz=text}}</nowiki>" .
|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=La valeur est le texte traduit dans la langue de code ''xx'' (le nom du paramètre ''xx'' peut être n’importe quel code langue supporté (standard BCP 47 / ISO 639-1), et vous pouvez indiquer autant de paramètres que nécessaire pour chaque langue de traduction).
|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-ja=言語「xx」で翻訳された文字。 (パラメーター名「xx」は(BCP 47/ISO 639-1)なら何でも大丈夫で、翻訳する言語ごとにいくつでも指定可能です) もし特定の言語でメッセージを表示させたくない場合(あるいはデフォルト値として)、「xx=~」と記述してください。
|2d-mk=Текст на јазикот ''xx''. ''xx'' може да бидат било кои поддржани јазици (BCP 47/ISO 639-1).
|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>”。
|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
|2stat=optional
|2type=string
|2type=string


|3=default
|3=default
| 3label = Default Fallback
|3label=Default fallback
|3d-en=Default text in case one of the "xx" languages is not the language of user's preferences. By default, the English version will be shown, if provided.
|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.
|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é.
|3d-ja=デフォルト言語の文字。上記の「xx」言語の中にユーザが指定した言語が含まれていない場合に、このデフォルト・オプションを使います。通常はデフォルトとして英語(en)で表示されます。
|3d-ja=デフォルト言語の文字。上記の「xx」言語の中にユーザが指定した言語が含まれていない場合に、このデフォルト・オプションを使います。通常はデフォルトとして英語(en)で表示されます。
|3def=<nowiki>{{{en|}}}</nowiki> (English version)
|3def=<nowiki>{{{en|}}}</nowiki> (English version)
Line 36: Line 38:


|4=lang
|4=lang
| 4label = Language Code
|4label=Language code
|4d={{Language-code-documentation}}
|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.
<nowiki>{{#if:{{{lang|}}}|{{{lang}}}|{{int:Lang}}}}</nowiki> is not necessary.
|4def-en=Value of <nowiki>{{Int:Lang}}</nowiki>(the preferred language of the visitor viewing the page).
|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-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>”の値 (ページを閲覧しているビジターの使用言語)。
|4def-ja=<nowiki>{{int:Lang}}</nowiki>の値 (ページを閲覧しているビジターの使用言語)。
|4stat=optional-
|4stat=optional-
|4type=string
|4type=string


|5=nocat
|5=nocat
| 5label = No Category?
|5label=No category?
|5d-en="nocat=1" will overwrite the default behavior of tracking uses without "en" or "default" options.
|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-ja=言語オプションに「en」や「default」オプションがないページには自動的にカテゴリCategory:LangSwitch template without default versionに追加され、"nocat=1" はデフォルト動作を上書きします。
|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-
|5stat=optional-
|5type=string
|5type=string
Line 54: Line 56:
|example=
|example=
|usage-notes={{LangSwitch
|usage-notes={{LangSwitch
  |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.
|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.
|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.
  }}
}}
 
|seealso=
|seealso=
* {{tl|Autotranslate}} for template internationalization (i18n) mechanism for templates that use ''named'' parameters
* {{Tl|Autotranslate}} for template internationalization (i18n) mechanism for templates that use ''named'' parameters
* {{tl|GetFallback}}, {{tl|Fallback}}, {{tl|Translation table}}
* {{Tl|GetFallback}}, {{tl|Fallback}}, {{tl|Translation table}}
* {{tl|Multilingual link}}
* {{Tl|Multilingual link}}
* [[:Category:Internationalization templates using LangSwitch]]
* [[:Category:Internationalization templates using LangSwitch]]
|setscats=[[:Category:Internationalization templates using LangSwitch]]
|setscats=[[:Category:Internationalization templates using LangSwitch]]
|type=
|type=
Line 76: Line 80:


=== Without a default option ===
=== Without a default option ===
Here are a few examples showing template behavior for three languages: English, Italian and Corsu, which defaults to Italian if Corsu text is not available:
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):


{|class="wikitable"
{|class="wikitable"
Line 86: Line 90:
!scope="col"| lang=co
!scope="col"| lang=co
|-
|-
| No en; default
| No en; default
| {{Tlx|LangSwitch{{{sandbox|}}}|it{{=}}Italian|default{{=}}default}}
| {{Tlx|LangSwitch{{{sandbox|}}}|it{{=}}Italian|default{{=}}default}}
| {{LangSwitch{{{sandbox|}}}|it=Italian|default=default|lang=en}}
| {{LangSwitch{{{sandbox|}}}|it=Italian|default=default|lang=en}}
Line 92: Line 96:
| {{LangSwitch{{{sandbox|}}}|it=Italian|default=default|lang=co}}
| {{LangSwitch{{{sandbox|}}}|it=Italian|default=default|lang=co}}
|-
|-
| No en; no default
| No en; no default
| {{Tlx|LangSwitch{{{sandbox|}}}|it{{=}}Italian|co{{=}}Corsu}}
| {{Tlx|LangSwitch{{{sandbox|}}}|it{{=}}Italian|co{{=}}Corsu}}
| {{LangSwitch{{{sandbox|}}}|it=Italian|co=Corsu|lang=en|nocat=1}}<ref name="c">would add [[:Category:LangSwitch template without default version]]</ref>
| {{LangSwitch{{{sandbox|}}}|it=Italian|co=Corsu|lang=en|nocat=1}}<ref name="c">would add [[:Category:LangSwitch template without default version]]</ref>
Line 98: Line 102:
| {{LangSwitch{{{sandbox|}}}|it=Italian|co=Corsu|lang=co|nocat=1}}<ref name="c"/>
| {{LangSwitch{{{sandbox|}}}|it=Italian|co=Corsu|lang=co|nocat=1}}<ref name="c"/>
|-
|-
| en; default
| en; default
| {{Tlx|LangSwitch{{{sandbox|}}}|en{{=}}English|co{{=}}Corsu|default{{=}}default}}
| {{Tlx|LangSwitch{{{sandbox|}}}|en{{=}}English|co{{=}}Corsu|default{{=}}default}}
| {{LangSwitch{{{sandbox|}}}|en=English|co=Corsu|default=default|lang=en}}
| {{LangSwitch{{{sandbox|}}}|en=English|co=Corsu|default=default|lang=en}}
Line 104: Line 108:
| {{LangSwitch{{{sandbox|}}}|en=English|co=Corsu|default=default|lang=co}}
| {{LangSwitch{{{sandbox|}}}|en=English|co=Corsu|default=default|lang=co}}
|-
|-
| en; no default
| en; no default
| {{Tlx|LangSwitch{{{sandbox|}}}|en{{=}}English|co{{=}}Corsu}}
| {{Tlx|LangSwitch{{{sandbox|}}}|en{{=}}English|co{{=}}Corsu}}
| {{LangSwitch{{{sandbox|}}}|en=English|co=Corsu|lang=en}}
| {{LangSwitch{{{sandbox|}}}|en=English|co=Corsu|lang=en}}
Line 110: Line 114:
| {{LangSwitch{{{sandbox|}}}|en=English|co=Corsu|lang=co}}
| {{LangSwitch{{{sandbox|}}}|en=English|co=Corsu|lang=co}}
|-
|-
| en; skip default
| en; skip default
| {{Tlx|LangSwitch{{{sandbox|}}}|en{{=}}English|co{{=}}Corsu|default{{=}}~}}
| {{Tlx|LangSwitch{{{sandbox|}}}|en{{=}}English|co{{=}}Corsu|default{{=}}~}}
| {{LangSwitch{{{sandbox|}}}|en=English|co=Corsu|default=~|lang=en}}
| {{LangSwitch{{{sandbox|}}}|en=English|co=Corsu|default=~|lang=en}}
Line 116: Line 120:
| {{LangSwitch{{{sandbox|}}}|en=English|co=Corsu|default=~|lang=co}}
| {{LangSwitch{{{sandbox|}}}|en=English|co=Corsu|default=~|lang=co}}
|-
|-
| en; empty default
| en; empty default
| {{Tlx|LangSwitch{{{sandbox|}}}|en{{=}}English|co{{=}}Corsu|default{{=}}}}
| {{Tlx|LangSwitch{{{sandbox|}}}|en{{=}}English|co{{=}}Corsu|default{{=}}}}
| {{LangSwitch{{{sandbox|}}}|en=English|co=Corsu|default=|lang=en}}
| {{LangSwitch{{{sandbox|}}}|en=English|co=Corsu|default=|lang=en}}
Line 122: Line 126:
| {{LangSwitch{{{sandbox|}}}|en=English|co=Corsu|default=|lang=co}}
| {{LangSwitch{{{sandbox|}}}|en=English|co=Corsu|default=|lang=co}}
|-
|-
| Skip en; default
| Skip en; default
| {{Tlx|LangSwitch{{{sandbox|}}}|en{{=}}~|it{{=}}Italian|default{{=}}default}}
| {{Tlx|LangSwitch{{{sandbox|}}}|en{{=}}~|it{{=}}Italian|default{{=}}default}}
| {{LangSwitch{{{sandbox|}}}|en=~|it=Italian|default=default|lang=en}}
| {{LangSwitch{{{sandbox|}}}|en=~|it=Italian|default=default|lang=en}}
Line 128: Line 132:
| {{LangSwitch{{{sandbox|}}}|en=~|it=Italian|default=default|lang=co}}
| {{LangSwitch{{{sandbox|}}}|en=~|it=Italian|default=default|lang=co}}
|-
|-
| Skip en; no default
| Skip en; no default
| {{Tlx|LangSwitch{{{sandbox|}}}|en{{=}}~|it{{=}}Italian}}
| {{Tlx|LangSwitch{{{sandbox|}}}|en{{=}}~|it{{=}}Italian}}
| {{LangSwitch{{{sandbox|}}}|en=~|it=Italian|lang=en}}
| {{LangSwitch{{{sandbox|}}}|en=~|it=Italian|lang=en}}
Line 134: Line 138:
| {{LangSwitch{{{sandbox|}}}|en=~|it=Italian|lang=co}}
| {{LangSwitch{{{sandbox|}}}|en=~|it=Italian|lang=co}}
|-
|-
| Empty en; no default
| Empty en; no default
| {{Tlx|LangSwitch{{{sandbox|}}}|en{{=}}|it{{=}}Italian}}
| {{Tlx|LangSwitch{{{sandbox|}}}|en{{=}}|it{{=}}Italian}}
| {{LangSwitch{{{sandbox|}}}|en=|it=Italian|lang=en}}<ref name="c"/>
| {{LangSwitch{{{sandbox|}}}|en=|it=Italian|lang=en}}<ref name="c"/>
Line 140: Line 144:
| {{LangSwitch{{{sandbox|}}}|en=|it=Italian|lang=co}}<ref name="c"/>
| {{LangSwitch{{{sandbox|}}}|en=|it=Italian|lang=co}}<ref name="c"/>
|-
|-
| en; default; skip it
| en; default; skip it
| {{Tlx|LangSwitch{{{sandbox|}}}|en{{=}}English|it{{=}}~|co{{=}}Corsu|default{{=}}default}}
| {{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=en}}
Line 146: Line 150:
| {{LangSwitch{{{sandbox|}}}|en=English|it=~|co=Corsu|default=default|lang=co}}
| {{LangSwitch{{{sandbox|}}}|en=English|it=~|co=Corsu|default=default|lang=co}}
|-
|-
| en; default; empty it
| en; default; empty it
| {{Tlx|LangSwitch{{{sandbox|}}}|en{{=}}English|it{{=}}|co{{=}}Corsu|default{{=}}default}}
| {{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=en}}
Line 152: Line 156:
| {{LangSwitch{{{sandbox|}}}|en=English|it=|co=Corsu|default=default|lang=co}}
| {{LangSwitch{{{sandbox|}}}|en=English|it=|co=Corsu|default=default|lang=co}}
|-
|-
| en; no default; skip it
| en; no default; skip it
| {{Tlx|LangSwitch{{{sandbox|}}}|en{{=}}English|it{{=}}~|co{{=}}Corsu}}
| {{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=en}}
Line 158: Line 162:
| {{LangSwitch{{{sandbox|}}}|en=English|it=~|co=Corsu|lang=co}}
| {{LangSwitch{{{sandbox|}}}|en=English|it=~|co=Corsu|lang=co}}
|-
|-
| Forced "lang=co"
| Forced "lang=co"
| {{Tlx|LangSwitch{{{sandbox|}}}|en{{=}}English|co{{=}}Corsu|default{{=}}default|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}}
Line 181: Line 185:


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.
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:").  
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:”).
 
=== 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>” and<br /> “<code><nowiki>bleu{{LangSwitch |fr=~ |en=&amp;#32;({{I18n/blue}}) }}</nowiki></code>”<br />
are conditionally append parenthesized translations of “red” (when the current user language is ''not'' English) and of “bleu” (when the current user language is ''not'' French):


=== Other examples ===
{|class="wikitable"
* "<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>) may be combined in the same parameter name, when these languages are mapped to the same output text (this helps simplifying the usage); however this still does not work correctly with the language code <code>en</code> if there's no <code>default=</code> parameter and no <code>en=</code> parameter specified separately (if this is not the case, this template still returns a usage error message<ref name="c"/>).
* <code><nowiki>red{{LangSwitch |en=~ |default=&amp;#32;({{i18n/red}}) }}</nowiki></code> and <code><nowiki>bleu{{LangSwitch |fr=~ |en=&amp;#32;({{i18n/blue}}) }}</nowiki></code>
{|class="wikitable" style="float:left;margin:2px 3.2em"
|-
|-
|style="background:#A00;color:#FFF"| red{{LangSwitch |en=~ |default=&#32;({{i18n/red}}) }}
|style="background:#A00;color:#FFF"| red{{LangSwitch |en=~ |default=&#32;({{I18n/red}}) }}
|style="background:#00A;color:#FFF"| bleu{{LangSwitch |fr=~ |en=&#32;({{i18n/blue}}) }}
|style="background:#00A;color:#FFF"| bleu{{LangSwitch |fr=~ |en=&#32;({{I18n/blue}}) }}
|}
|}
:: conditionally append parenthesized translations of "red" (when the current user language is ''not'' English) and of "bleu" (when the current user language is ''not'' French).{{Clear|left}}
 


== Notes ==
== Notes ==

Revision as of 10:29, 1 April 2025

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.

The template automatically sets the following categories: Category:Internationalization templates using LangSwitch

Usage

{{LangSwitch
 |en =
 |xx =
 |default =
}}

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.

Template parameters

<templatedata>JSON</templatedata> ./. {{TemplateBox}}
TemplateData

TemplateData is a way to store information about template parameters (the description of those and of the whole template) for both humans and machines. It is used by VisualEditor and possibly other tools like Upload Wizard.


Existing template documentation
At Wikimedia Commons, it is recommended to use {{TemplateBox}} with either ‎useTemplateData=1 or ‎useTemplateData=only on the ‎/doc subpage and transcluding it with {{Documentation}} into the template. ‎<nowiki>-tags can be wrapped around the arguments, if required, to avoid templates being expanded.

Newly created template documentation and imports
Another option, especially for imported templates, or for users with JSON experience, is placing raw ‎<templatedata>-tags into the Wikitext of the template, as described in various Wikipediae.


Wikipedia's help about TemplateDataCommons-specific information

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.

Template parameters

This template prefers block formatting of parameters.

ParameterDescriptionTypeStatus
Default fallbackdefault

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.

Default
{{{en|}}} (English version)
Stringsuggested
Englishen

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=~”.

Stringrequired
Language codelang

Language code (only needs to be provided if the language displayed is to be fixed and independent of the user’s preferences). Note that specifying “{{#if: {{{lang|}}} | {{{lang|}}} | {{Int:Lang}} }}” in this value is usually not necessary, unless one wants to override the default target language.

Default
Value of “{{Int:Lang}}” (the preferred language of the visitor viewing the page).
Stringoptional
No category?nocat

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

Stringoptional
xx

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 “{{LangSwitch |xx/yy/zz=text }}”, which is equivalent to “{{LangSwitch |xx=text |yy=text |zz=text }}”. You can specify as many such parameters as needed for each translated language.

Stringoptional

Additional information

The template is intended to be used in the following namespaces: no namespace specified

The template is intended to be used by the following user groups: all users

Relies on:
Module:Fallback

See also

Localization

This template is not intended to be localized.

Help for choosing the right template for your use case:
I18n templates: {{Multilingual description|lang=
|de,en,default=Deutsch/​English
|fr=français
|...
}}
{{de|Deutsch}}
{{en|English}}
{{fr|français}}
...
{{LangSwitch|lang=
|de,en,default=Deutsch/​English
|fr=français
|...
}}
{{Autotranslate}} {{tnt}} Language-aware transclusion
Recommended use at Categories, galleries File description pages (deprecated, can be safely replaced by {{Multilingual description}}) Small templates, whenever the previous options are not suitable (removes the visual indication of the language before each translated text) Data tables with translated cells or larger templates, when used on pages that do not have language subpages (e.g. not having Main page/en, Main page/de) and where the language displayed will be automatically determined by the language set in user preferences Data tables with translated cells or larger templates, when used on pages that do have language subpages; most of the time these will be pages prepared with the Translate Extension Data tables with translated cells or larger templates, when used on pages that do have language subpages; the transcluded page needs to be prepared with the Translate Extension, the transcluding page needs to be either prepared with the Translate Extension, or have the page language set by a translation administrator
Requires JavaScript enabled for folding Yes No
Folding can be disabled by user Yes No
Folding is done server-side No Yes
Folding when at least n languages are provided 1 (all translations are shown without folding if the preferred language selected by the user has no matching translation) 4 1
Detection of duplicate, incorrect, or unsupported language codes Yes No Yes Duplicate language codes are impossible by design. Incorrect or unsupported codes are never displayed, but not reported. The Translate extension's interface (if it's used on the translation subpages) doesn't let the user create translations with invalid codes, but other methods (e.g. entering the translation's URL directly) allow it without any warning.
Allows the same translation to be used for several languages Yes No Yes
Supports language fallbacks No Yes No
Collation order of languages (when not folded) Consistent order by native language name, languages grouped by script:
  • LTR scripts: Latin, Latin or Cyrillic, Cyrillic, Greek, other simple LTR alphabets (Armenian, Georgian, etc.), abugidas (North Indian, South Indian, other South-East Asian, etc.), syllabaries (European, American, African, Asian), Korean alphabets (basic Jamos, Hangul including some sinograms), Japanese syllabaries (including some sinograms), sinograms (including some syllabaries)
  • RTL scripts: Hebrew, Arabic, other RTL abjads (Divehi, etc.), RTL syllabaries (N'ko)
As provided by the user in the wikitext (any inconsistent order may be difficult to lookup visually) N/A
Search indexing issues No (all translations are included on the same page, however search results may be less relevant with many languages mixed) Yes (may not index all languages depending on search engines, unless there's a list of links for visiting other languages) Partially (where used; language subpages of templates are indexed) No (translated pages should include a <languages/> navigation bar for visiting other languages)
Page size issues Yes (may exhaust size or time limits in the wiki parser if many languages are included; larger pages to download for all visitors; slower navigation for visitors with slow Internet access; may be costly for visitors with limited data plans) No (only the content for the selected language or a suitable fallback language is present in the generated page)
Contains expensive parser functions No Yes, checks for several translations along the fallback chain until finds a suitable Yes, 2–4 checks per call No

Examples

Without a default option

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

Test Code lang=en lang=it lang=co
No en; default {{LangSwitch|it=Italian|default=default}} default Italian Italian
No en; no default {{LangSwitch|it=Italian|co=Corsu}} LangSwitch Error: no default[1] LangSwitch Error: no default[1] LangSwitch Error: no default[1]
en; default {{LangSwitch|en=English|co=Corsu|default=default}} English default Corsu
en; no default {{LangSwitch|en=English|co=Corsu}} English English Corsu
en; skip default {{LangSwitch|en=English|co=Corsu|default=~}} English Corsu
en; empty default {{LangSwitch|en=English|co=Corsu|default=}} English English Corsu
Skip en; default {{LangSwitch|en=~|it=Italian|default=default}} Italian Italian
Skip en; no default {{LangSwitch|en=~|it=Italian}} Italian Italian
Empty en; no default {{LangSwitch|en=|it=Italian}} LangSwitch Error: no default[1] Italian LangSwitch Error: no default[1]
en; default; skip it {{LangSwitch|en=English|it=~|co=Corsu|default=default}} English Corsu
en; default; empty it {{LangSwitch|en=English|it=|co=Corsu|default=default}} English default Corsu
en; no default; skip it {{LangSwitch|en=English|it=~|co=Corsu}} English Corsu
Forced "lang=co" {{LangSwitch|en=English|co=Corsu|default=default|lang=co}} Corsu Corsu Corsu

Default option

The default option is intended for providing more language independent option. For example:

{{LangSwitch
|de={{Wd|Warschau}}
|en={{W|Warsaw}}
|fr={{Wf|Varsovie}}
|ja={{W日|ワルシャワ}}
|pl={{WP|Warszawa}}
|ru={{Wr|Варшава}}
|default=[[d:Q270]]
}}

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 {{W|Q270||d}} is equivalent to the shorter [[d:Q270]] (it just does not show the “d:”).

Combination of multiple languages in the same option

{{LangSwitch |de=Grün |es/it/pt=Verde |fr=Vert |en=Green |lang={{{lang|{{int:lang}}}}} }}” gives “Green” for the language with code en.

Note that several language codes (separated by /) 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 en if there’s no parameter default= or en= specified separately (when this occurs, this template still returns a usage error message[1]).

Returning empty texts

red{{LangSwitch |en=~ |default=&#32;({{I18n/red}}) }}” and
bleu{{LangSwitch |fr=~ |en=&#32;({{I18n/blue}}) }}
are conditionally append parenthesized translations of “red” (when the current user language is not English) and of “bleu” (when the current user language is not French):

red bleu (blue)


Notes

Cookies help us deliver our services. By using our services, you agree to our use of cookies.