Template:LangSwitch/doc

维基共享资源,媒体文件资料库
跳转到导航 跳转到搜索

(本说明文件的该部分只有有限数量的语言版本。)

从已翻译的多语言文本组中输出以特定语言的文本。显示语言为用户设置语言,或是由GetFallback定义的后备语言。

本模板自动设置以下分类: Category:Internationalization templates using LangSwitch

用法

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

模板参数

<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

从已翻译的多语言文本组中输出以特定语言的文本。显示语言为用户设置语言,或是由GetFallback定义的后备语言。

模板参数

此模板首选参数换行的代码块格式。

参数描述类型状态
Default Fallbackdefault

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|}}} (English version)
字符串推荐
Englishen

英文文本。除非通过“default”设置默认显示语言,否则将在用户偏好语言的翻译文本缺失的情况下显示英文文本。如果不想在用户使用英语时显示任何文本,请指定“en=~”。

字符串必需
Language Codelang

语言代码(只有在显示语言待修复,且独立于用户参数设置时才需要提供)。 {{#if:{{{lang|}}}|{{{lang}}}|{{int:Lang}}}} is not necessary.

默认值
Value of {{int:Lang}} (the preferred language of the visitor viewing the page).
字符串可选
No Category?nocat

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

字符串可选
xx

“xx”语言的翻译文本,参数名“xx”可以是任何来自BCP 47或ISO 639-1的语言代码,可根据需要增加可能多的翻译语言。如果希望在某种特定语言中不显示任何信息(故意留空),请使用“xx=~”。可以使用“{{LangSwitch|xx/yy/zz=text}}”在多种语言中使用一个文本中,相当于“{{LangSwitch|xx=text|yy=text|zz=text}}”。

字符串可选

附加信息

本模板可以用于以下名字空间: 未指定名字空间

本模板可以于以下用户组使用: 所有用户

使用的模板:
Module:Fallback

参看

(本说明文件的该部分只有有限数量的语言版本。)

本地化

本模板不用本地化。

(本说明文件的该部分只有有限数量的语言版本。)

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

Example for more

<kbd>LangSwitch|de=Grün|es/it/pt=Verde|fr=Vert|en=Green |lang={{{lang|{{int:lang}}}}}}}</kbd> will give Green for language zh


red
(紅色)
bleu
(藍色)


This example will translate red when not English, and bleu when not French

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

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

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