Template:LangSwitch

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


Documentation icon Documentationviewedithistorypurge

This documentation is transcluded from Template:LangSwitch/doc.

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 =
}}

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.

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.

Template parameters

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

Default
{{{en|}}} (English version)
Stringoptional
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=~".

Stringrequired
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 {{#if:{{{lang|}}}|{{{lang}}}|{{int:Lang}}}}.

Default
Value of {{int:Lang}} (the preferred language of the visitor viewing the page).
Stringoptional
nocat

"nocat=1" will overwrite the default behavior of tracking uses without "en" or "default" options.

Stringoptional
xx

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 "~" if you do not want any message (or default) in some specific 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}} {{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

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:

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 Italian LangSwitch Error: no default
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=[[: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.

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.

Notes

  1. a b c would add Category:LangSwitch template without default version