Template:LangSwitch/doc

From Wikimedia Commons, the free media repository
Jump to: navigation, search

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 (as determined by GetFallback).

The template automatically sets the following categories: Category:LangSwitch template without default version

Usage

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

Template parameters

 Parameter text is empty
<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 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 or the template as described in various Wikipediae.

Discussion
There is an ongoing discussion about that matter. Feel invited to comment if you are experienced in either way, your time permits and if you like to share your opinion or to make a suggestion.


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 (as determined by GetFallback).

Template parameters
Parameter Description Type Default Auto value Status
default 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. string {{{en|}}} (English version) empty optional
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=~". string empty empty required
lang Language code (only needs to be provided if the language displayed is to be fixed and independent of the user’s preferences).. Many templates use <code>{{#if:{{{lang|}}}|{{{lang|}}}|{{int:Lang}}}}</code>. string Value of {{int:Lang}} (the preferred language of the visitor viewing the page). empty optional
nocat "nocat=1" will overwrite the default behavior of tracking uses without "en" or "default" options. string empty empty optional
xx Translated text in language ''xx'' (the parameter name ''xx'' can be any supported language code, and you can specify as many such parameters as needed for each translated language). Use "~" if you do not want any message (or default) in some specific language. string empty empty optional

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 and module:fallbacklist

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}} {{en}}{{fr}} {{LangSwitch}} {{Autotranslate}} {{TNT}}
Requires JavaScript enabled for folding + +
Folding can be disabled by user + +
Folding is done server-side + + +
Folding when at least n languages are provided 1 4 1 1 1
Collation order of languages (when not folded) Latin, Latin or Cyrillic, Cyrillic, Greek, other simple LTR alphabets, Indic, other South Asian, Syllabaries, Hangul, Japanese scripts, Sinograms, Hebrew, Arabic languages as provided by the user in the wikitext
Search indexing issues ? partially (where used; language subpages of templates are indexed)
Recommended use at categories, galleries file description pages other pages incl. simple templates 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 larger templates when used on pages that do have language subpages; most of the time these will be pages prepared with the Translate Extension
Contains expensive parser functions + +

Examples

Here are a few examples showing template behavior for three languages: English, French and Corsu, which defaults to French if Corsu text is not available:

Test Code lang=en lang=fr lang=co
No En; default {{LangSwitch|fr=French|default=default}} default French French
No En; no default {{LangSwitch|fr=French|co=Corsu}} [1] French[1] Corsu[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=~|fr=French|default=default}} French French
Skip en; no default {{LangSwitch|en=~|fr=French}} French French
Empty en; no default {{LangSwitch|en=|fr=French}} French French
En; default; skip fr {{LangSwitch|en=English|fr=~|co=Corsu|default=default}} English Corsu
En; default; empty fr {{LangSwitch|en=English|fr=|co=Corsu|default=default}} English default Corsu
En; no default; skip fr {{LangSwitch|en=English|fr=~|co=Corsu}} English Corsu
Forced "lang=co" {{LangSwitch|en=English|co=Corsu|default=default|lang=co}} Corsu Corsu Corsu
  1. a b c would add Category:LangSwitch template without default version

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

{{LangSwitch
|de=[[:de:Warschau|Warschau]]
|en=[[:en:Warsaw|Warsaw]]
|fr=[[:fr:Varsovie|Varsovie]]
|ja=[[:ja:ワルシャワ|ワルシャワ]]
|pl=[[:pl:Warszawa|Warszawa]]
|default=[[d:Q270]]
}}

will provide 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.