Template:LangSwitch/doc

From PsychonautWiki
Jump to navigation Jump to 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

<poem>{{LangSwitch

|xx = 
|default = 
|en = 

}}</poem>

⧼templatedata-doc-params⧽

<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

<templatedata> {"description":{"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 (as determined by GetFallback).","en-gb":"","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.","ja":"翻訳されている多くの言語の中から、適切な言語でテキスト文字を表示する機能を提供します。その適切な言語とは、ユーザの好みに応じて言語セットで選択された言語、あるいは、(GetFallbackで定義される)自動システムで一番最適と思われる言語です。","mk":"Од разните постоечки преводи, го дава преводот на јазикот одбран во нагодувањата, или пак најсоодветниот резервен јазик (според утврденото во GetFallback)."},"params":{"default":{"default":"{{{en|}}} (English version)","deprecated":false,"description":{"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.","en-gb":"","ja":"デフォルト言語の文字。上記の「xx」言語の中にユーザが指定した言語が含まれていない場合に、このデフォルト・オプションを使います。通常はデフォルトとして英語(en)で表示されます。"},"label":"","required":false,"suggested":false,"type":"string"},"en":{"deprecated":false,"description":{"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=~\".","en-gb":"","ja":"英語言語の文字。下記のデフォルトオプションを設定していない場合で、ユーザが選択した言語セットに該当する翻訳がない場合、この英語テキストが通常使われます。もしユーザの使用言語が英語で何も文字を表示させたくない場合、「en=~」と記述してください。「en」オプションのないLangSwitchテンプレートはカテゴリCategory:LangSwitch template without default versionに自動的に追加されます。"},"label":"","required":true,"suggested":false,"type":"string"},"lang":{"default":"","deprecated":false,"description":"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}}}}.","label":"","required":false,"suggested":false,"type":"string"},"nocat":{"deprecated":false,"description":{"en":"\"nocat=1\" will overwrite the default behavior of tracking uses without \"en\" or \"default\" options.","en-gb":"","ja":"言語オプションに「en」や「default」オプションがないページには自動的にカテゴリCategory:LangSwitch template without default versionに追加され、\"nocat=1\" はデフォルト動作を上書きします。"},"label":"","required":false,"suggested":false,"type":"string"},"xx":{"deprecated":false,"description":{"en":"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.","en-gb":"","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é, et vous pouvez indiquer autant de paramètres que nécessaire pour chaque langue de traduction).","ja":"言語「xx」で翻訳された文字。 (パラメーター名「xx」はサポートされている言語コードなら何でも大丈夫で、翻訳する言語ごとにいくつでも指定可能です) もし特定の言語でメッセージを表示させたくない場合(あるいはデフォルト値として)、「xx=~」と記述してください。","mk":"текст на јазикот xx. xx може да бидат било кои поддржани јазици."},"label":"","required":false,"suggested":false,"type":"string"}},"sets":[]} </templatedata>

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

⧼Seealso⧽

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

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.