Template:LangSwitch: Difference between revisions

From FlightGear wiki
Jump to navigation Jump to search
m (Doc style)
(→‎Known issues: Hmm. The template assumes that there is text for the language given by the lang parameter. It was only meant for debugging and demonstration purposes when written.)
 
(10 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{#if: {{{lang|}}} | {{{ {{{lang}}} }}} | {{#if: {{{ {{lc: {{#titleparts: {{PAGENAME}} | 1}} }}| }}} | {{{ {{lc: {{#titleparts: {{PAGENAME}} | 1}} }} }}} | {{{en|}}} }} }}<noinclude>
{{#if: {{{lang|}}} <!-- Is lang defined or non-empty? -->
| <!-- If lang is defined, try use the language code in that parameter. -->
  {{{ {{{lang}}} }}}
| <!-- If lang is empty or undefined, try use the language code of the page. -->
  {{#if: {{{ {{lc: {{#titleparts: {{PAGENAME}} | 1}} }}| }}} <!-- Does the page have a language prefix/language code? -->
  | <!-- If the page does have a language prefix, use the the contents of the parameter with that language code. -->
    {{{ {{lc: {{#titleparts: {{PAGENAME}} | 1}} }} }}}
  | <!-- If lang is empty or undefined and there is no language prefix, use the English content. -->
    {{{en|}}}
  }}
}}<noinclude>
{{Informative template|1=
{{Informative template|1=
== Goal ==
== Goal ==
Line 7: Line 17:


The language the text will be shown in depends on the two letter language code between the page namespace and the page title, for example [[Talk:De/HB Radio-NAV|Talk:'''De'''/HB Radio-NAV]].  If a parameter with a text is not available in the language of the page or is empty, the English text will be shown instead provided it is available.
The language the text will be shown in depends on the two letter language code between the page namespace and the page title, for example [[Talk:De/HB Radio-NAV|Talk:'''De'''/HB Radio-NAV]].  If a parameter with a text is not available in the language of the page or is empty, the English text will be shown instead provided it is available.
__TOC__
__TOC__


Line 15: Line 24:
For testing and demonstration purposes the named parameter '''lang''' can be used to select a different language than the language of the page the template is used on.
For testing and demonstration purposes the named parameter '''lang''' can be used to select a different language than the language of the page the template is used on.


  <nowiki>{{</nowiki>'''LangSwitch''' <nowiki>|</nowiki>''de='' <nowiki>|</nowiki>''en='' <nowiki>|</nowiki>''es='' <nowiki>|</nowiki>''fr='' <nowiki>|</nowiki>''nl='' <nowiki>|</nowiki>''ru='' ... <nowiki>|</nowiki>''lang=''<nowiki>}}</nowiki>
  <nowiki>{{</nowiki>'''LangSwitch''' <nowiki>|</nowiki>''de='' <nowiki>|</nowiki>en= <nowiki>|</nowiki>''es='' <nowiki>|</nowiki>''fr='' <nowiki>|</nowiki>''nl='' <nowiki>|</nowiki>''ru='' ... <nowiki>|</nowiki>''lang=''<nowiki>}}</nowiki>


  <nowiki>{{</nowiki>'''LangSwitch'''
  <nowiki>{{</nowiki>'''LangSwitch'''
  <nowiki>|</nowiki> ''de'' =  
  <nowiki>|</nowiki> ''de'' =  
  <nowiki>|</nowiki> ''en'' =  
  <nowiki>|</nowiki> en =  
  <nowiki>|</nowiki> ''es'' =  
  <nowiki>|</nowiki> ''es'' =  
  <nowiki>|</nowiki> ''fr'' =  
  <nowiki>|</nowiki> ''fr'' =  
Line 28: Line 37:
  <nowiki>}}</nowiki>
  <nowiki>}}</nowiki>


== Examples ==
=== Translating templates ===
=== Translating templates ===
The template is mainly used for translating templates.
The template is mainly used for translating templates.


Do note that many templates are based on tables and have to start from the beginning of the line, which is accomplished like in the below example, and that inserting blank lines will alter the way the template is rendered.
{{inote|Many templates are based on tables and thus have to start from the beginning of the line.  That is accomplished by putting them on a new line like in the example below.}}
 
{{inote|Inserting blank lines will alter the way the template is rendered.}}


  <nowiki>{{LangSwitch
  <nowiki>{{LangSwitch
Line 44: Line 56:
=== Using the lang parameter ===
=== Using the lang parameter ===
For testing and demonstration purposes the the '''lang ''' parameter can be used to override the automatic language selection.
For testing and demonstration purposes the the '''lang ''' parameter can be used to override the automatic language selection.
<pre><!-- Caveat: Google translated -->
 
<nowiki><!-- Caveat: Google translated -->
{{LangSwitch
{{LangSwitch
|de = Hallo Welt!
| de = Hallo Welt!
|en = Hello World!
| en = Hello World!
|es = ¡Hola Mundo!
| es = ¡Hola Mundo!
|fr = Bonjour tout le monde!
| fr = Bonjour tout le monde!
|nl = Hello World!
| nl = Hello World!
|ru = Привет мир!
| ru = Привет мир!
|lang = fr
| lang = fr
}}
}}</nowiki>
</pre>


{{LangSwitch
{{LangSwitch
Line 66: Line 78:
}}
}}


== Copyable sample ==
Please uncomment used entries, in essence by dragging and dropping <code>&lt;!--</code> to the left of the name of the language, like as with English in the example below.


<nowiki>{{LangSwitch
<!-- | ca =  Catalan -->
<!-- | de =  German -->
| en =  <!-- English -->
<!-- English/default text here -->
<!-- | es =  Spanish -->
<!-- | fa =  Persian -->
<!-- | fi =  Finnish -->
<!-- | fr =  French -->
<!-- | it =  Italian -->
<!-- | ja =  Japanese -->
<!-- | nl =  Dutch -->
<!-- | pl =  Polish -->
<!-- | pt =  Portugese -->
<!-- | ru =  Russian -->
<!-- | sl =  Slovenian -->
<!-- | sr =  Serbian -->
<!-- | sv =  Swedish -->
<!-- | zh =  Chinese -->
| lang = {{{lang|}}}
}}</nowiki>


=== Examples of language codes ===
== Known issues ==
{{{!}} class="wikitable"
Using some characters like equal signs ('''<nowiki>=</nowiki>''') and pipes/vertical strokes ('''<nowiki>|</nowiki>''') inside template parameters will break the template.  Do note that pipes will break tables and that this workaround have to be used for tables.  Ways around this is to either use {{tl|{{=}}}}, {{tl|!}}, {{tl|!!}} or {{tl|!-}}, or &lt;nowiki&gt;<nowiki>=</nowiki>&lt;/nowiki&gt;, &lt;nowiki&gt;<nowiki>|</nowiki>&lt;/nowiki&gt;, &lt;nowiki&gt;<nowiki>||</nowiki>&lt;/nowiki&gt; or &lt;nowiki&gt;<nowiki>|</nowiki>-&lt;/nowiki&gt;.
! ISO 639-1
two letter code
! English name of language
{{!-}}
{{!}} ca {{!!}} Catalan
{{!-}}
{{!}} de {{!!}} German
{{!-}}
{{!}} en {{!!}} English
{{!-}}
{{!}} es {{!!}} Spanish
{{!-}}
{{!}} fa {{!!}} Farsi
{{!-}}
{{!}} fi {{!!}} Finnish
{{!-}}
{{!}} fr {{!!}} French
{{!-}}
{{!}} nl {{!!}} Dutch
{{!-}}
{{!}} pl {{!!}} Polish
{{!-}}
{{!}} pt {{!!}} Portugese
{{!-}}
{{!}} ru {{!!}} Russian
{{!-}}
{{!}} sv {{!!}} Swedish
{{!-}}
{{!}} zh {{!!}} Chinese
{{!}}}


== Known issues ==
The template currently does not check if there is text in the language used by the '''lang''' override parameter.
Using equal signs inside template parameters will break the template.  Two ways around this is to either use {{tl|{{=}}}} or &lt;nowiki&gt;=&lt;/nowiki&gt;.


== Related content ==
== Related content ==

Latest revision as of 23:31, 17 April 2019


The following template description is not displayed when the template is inserted in an article.

Goal

This template will show texts in different languages depending on the language of the page it is placed on.

It is mainly meant for translation of contents within templates so that a single template can be used in pages of different languages, rather than having to be translated with one template for each language.

The language the text will be shown in depends on the two letter language code between the page namespace and the page title, for example Talk:De/HB Radio-NAV. If a parameter with a text is not available in the language of the page or is empty, the English text will be shown instead provided it is available.

Usage

The parameters of this template corresponds to the ISO 639-1 two letter language code for the language to be used in that parameter.

For testing and demonstration purposes the named parameter lang can be used to select a different language than the language of the page the template is used on.

{{LangSwitch |de= |en= |es= |fr= |nl= |ru= ... |lang=}}
{{LangSwitch
| de = 
| en = 
| es = 
| fr = 
| nl = 
| ru = 
... 
| lang = 
}}

Examples

Translating templates

The template is mainly used for translating templates.

Note Many templates are based on tables and thus have to start from the beginning of the line. That is accomplished by putting them on a new line like in the example below.

Note Inserting blank lines will alter the way the template is rendered.

{{LangSwitch
| en =  <!-- English -->
{{ Template with English contents }}
| de =  <!-- German -->
{{ Template with German contents }}
| fr =  <!-- French -->
{{ Template with French contents }}
}}

Using the lang parameter

For testing and demonstration purposes the the lang parameter can be used to override the automatic language selection.

<!-- Caveat: Google translated -->
{{LangSwitch
| de = Hallo Welt!
| en = Hello World!
| es = ¡Hola Mundo!
| fr = Bonjour tout le monde!
| nl = Hello World!
| ru = Привет мир!
| lang = fr
}}

Bonjour tout le monde!

Copyable sample

Please uncomment used entries, in essence by dragging and dropping <!-- to the left of the name of the language, like as with English in the example below.

{{LangSwitch
<!-- | ca =  Catalan -->
<!-- | de =  German -->
| en =  <!-- English -->
<!-- English/default text here -->
<!-- | es =  Spanish -->
<!-- | fa =  Persian -->
<!-- | fi =  Finnish -->
<!-- | fr =  French -->
<!-- | it =  Italian -->
<!-- | ja =  Japanese -->
<!-- | nl =  Dutch -->
<!-- | pl =  Polish -->
<!-- | pt =  Portugese -->
<!-- | ru =  Russian -->
<!-- | sl =  Slovenian -->
<!-- | sr =  Serbian -->
<!-- | sv =  Swedish -->
<!-- | zh =  Chinese -->
| lang = {{{lang|}}}
}}

Known issues

Using some characters like equal signs (=) and pipes/vertical strokes (|) inside template parameters will break the template. Do note that pipes will break tables and that this workaround have to be used for tables. Ways around this is to either use {{=}}, {{!}}, {{!!}} or {{!-}}, or <nowiki>=</nowiki>, <nowiki>|</nowiki>, <nowiki>||</nowiki> or <nowiki>|-</nowiki>.

The template currently does not check if there is text in the language used by the lang override parameter.

Related content