Difference between revisions of "Template:Engvar/doc"

From blackwiki
Jump to navigation Jump to search
imported>DePiep
(→‎Todo: rewrite the doc)
(reverting idiot's edit)
Line 3: Line 3:
  
 
== Usage ==
 
== Usage ==
This template can be used in templates that are used on pages with different '''English language variants''' (see [[WP:ENGVAR|ENGVAR]]): articles in en-UK and articles in en-US. At the moment only UK and US English are recognised.
+
This template can be used in templates that are used on pages with English language variants: articles in en-UK and articles in en-US. At the moment only UK and US English are recognised.
  
'''Article editor:''' When using the prepared template in an article, the editor can set its parameter  {{code|<nowiki>|engvar=en-UK</nowiki>}}. The template text now will use the provided en-UK variant of words. This parameter setting is only needed once in the template.
+
'''Article editor'''
 +
When using the template in an article, the editor can set its parameter  {{code|<nowiki>|engvar=en-UK</nowiki>}}. The template text now will use the provided en-UK variant of words. This parameter setting is only needed once in thetemplate.
  
'''In the template:''' So your template takes ''input parameter'' {{code|<nowiki>{{{engvar}}}</nowiki>}} as the language id. Internally, your template should have this code construct:
+
'''In the template'''
 +
So the template takes ''input parameter'' {{code|<nowiki>{{{engvar}}}</nowiki>}} Internally, the template has this construct:
 
<pre>
 
<pre>
 
...
 
...
Line 13: Line 15:
 
...
 
...
 
</pre>
 
</pre>
Depending on the engvar input, it returns one of the words.
+
Depending on the engvar input, it returns oneofthevalues.
  
===Language id===
+
'''Notes'''<br />
At this moment, the next language ids are recognised.<br />
+
'''Language ids''' that are recognised are:<br />
Used in article code (article editor; case insensitive):
+
# In article code (article editor; case insensitive):
* {{code|1=engvar= en-UK, UK, en-uk, uk}} &rarr; returns the en-UK word(s)
+
* {{code|1=engval= en-UK, UK, en-uk, uk}} &rarr; returns the en-UK value
* {{code|1=engvar= en-US, US, en-us, us}} &rarr; returns the en-US word(s)
+
* {{code|1=engval= en-US, US, en-us, us}} &rarr; returns the en-US value
* {{code|1=engvar= en, EN}} &rarr; returns the plain English word(s) (more on this below)
 
  
Used in template code (template editor):
+
# In template code (template editor):
* Here, always use the lowercase language id for your word definition: {{code|1=uk-en=Football}} (NOT {{code|1=uk-EN=Football}})
+
* Here, always use the lowercase language id: {{code|1=uk-en=Football}} (NOT {{code|1=uk-EN=Football}})
* Recognised language id's: {{code|1=en-uk= OR uk=, en-us= OR us=, en=}}
+
* Recognised language id's: {{code|1=en-uk=, uk=, en-us=, us=}}
  
===Unnamed parameters===
+
# '''Unnamed parameters''' in template code can be used:
In template code unnamed parameters can be used:
 
 
* Unnamed parameter 1=pass throught the {{code|<nowiki>{{{engvar}}}</nowiki>}} variable. Named: {{code|<nowiki>engvar={{{engvar}}}</nowiki>}}
 
* Unnamed parameter 1=pass throught the {{code|<nowiki>{{{engvar}}}</nowiki>}} variable. Named: {{code|<nowiki>engvar={{{engvar}}}</nowiki>}}
* Unnamed parameter 2=en-UK word(s)
+
* Unnamed parameter 2=en-UK definition
* Unnamed parameter 3=en-US word(s)
+
* Unnamed parameter 3=en-US definition
* Parameter "en=" cannot be unnamed.
 
  
 
<pre>
 
<pre>
<!-- The next four rows are equal in template code: -->
+
<!-- The next three rows are equal in template code: -->
 
...
 
...
 
| label= {{engvar| engvar={{{engvar|}}} | en-uk=Football | en-us=Soccer }}
 
| label= {{engvar| engvar={{{engvar|}}} | en-uk=Football | en-us=Soccer }}
 +
| label= {{engvar| 1={{{engvar|}}} | 2=Football | 3=Soccer }}
 
| label= {{engvar| 1={{{engvar|}}} | uk=Football | us=Soccer }}
 
| label= {{engvar| 1={{{engvar|}}} | uk=Football | us=Soccer }}
| label= {{engvar| {{{engvar|}}} | Football | Soccer }}
 
| label= {{engvar| 1={{{engvar|}}} | 2=Football | 3=Soccer }}
 
...
 
</pre>
 
 
===Plain "en" variant===
 
It is possible to define and use the plain English variant word(s) with id "en": {{code|1=en=Association football}}. From here, the article can ask for plain "en" by using {{code|1=engvar=en}}.
 
 
In the template code, this must ''always'' be a named parameter.
 
<pre>
 
...
 
| label= {{engvar| {{{engvar|}}} | Football | Soccer | en=Association football }}
 
 
...
 
...
 
</pre>
 
</pre>
  
===Default language id===
+
'''Plain "en" variant'''
'''Default behaviour 1:''' To force a default language id (a language that will be used when there is no input, or a blank input) use {{code|1=default=en-US}}.
 
<pre>
 
| label= {{engvar| {{{engvar}}} | Football | Soccer | default=en-US }}
 
</pre>
 
 
 
'''Default behaviour 2:''' Another default-behaviour can be used: in your template, provide parameter {{code|engvar}} with a default language id:
 
<pre>
 
| label= {{engvar| {{{engvar| en-US }}} | Football | Soccer | en=Association football }}
 
</pre>
 
This default last example will ''not'' use the default language when the engvar is a blank. Instead, the standard default word is returned (see below).This may occur in nested templates and pass-through variables.
 
 
 
===Default word(s)===
 
'''Default behaviour 3:'''
 
When the {{code|engvar}} value is not recognised (or the {{code|default}} language alternative you might have provided), then the ''default word(s)'' will be returned.
 
 
 
This default word(s) is determined as follows:
 
1st: the {{code|1=en=}} word(s) if entered<br />
 
2nd: the {{code|1=en-uk=}} (or uk) word(s) if entered<br />
 
3rd: the {{code|1=en-us=}} (or us) word(s) if entered<br />
 
4rd: a blank<br />
 
Clearly, this template tries to make a catch when possible. Blanks output avoided when possibble.
 
 
 
'''Default behaviour 4:''' From the above, it follows that entering {{code|1=engvar=en}} produces the default word(s) as described. This is intentionally and by definition. Still, it is preferred not to rely on this route, because it might not work as expected.
 
 
 
'''Notes on coding'''
 
* On the template side provide at least both UK and US word(s), and maybe the en-word(s). Do not rely on the Default-behaviour, ''even when it tests OK today''.
 
* Use named parameters for code clarity
 
* Do not rely on blank entries to return (do not use: {{code|1=<nowiki>en-UK=|...}}</nowiki>}}). It might be interpreted as absent, and so another word may be used.
 
 
 
===Full parameter list===
 
Parameter list:
 
<pre>
 
{{engvar
 
| engvar =
 
| en-uk  =
 
| en-us  =
 
| en    =
 
| default=
 
}}
 
</pre>
 
 
 
Or, equivalent names:
 
<pre>
 
{{engvar
 
| engvar =
 
| uk    =
 
| us    =
 
| en    =
 
| default=
 
}}
 
</pre>
 
 
 
Or, unnamed:
 
<pre>
 
{{engvar
 
|
 
|
 
|
 
| en    =
 
| default=
 
}}
 
</pre>
 
 
 
==Todo==
 
* Other English variants could be added
 
* Is there a definite list of English language variants, we should cover?
 
* Maybe a fallback can exist: if en-GB does not exist then use en-UK
 
* Rewrite this doc. ;-) <!--self reference me DePiep -->
 
  
==Examples==
+
Default and plain "en"
* See [[Template:Engvar/testcases]]
+
# When the engvar=value from the article is not recognised, te
  
 
== See also ==
 
== See also ==
* [[WP:ENGVAR]] about using a single variant in an article
 
  
 
<includeonly>
 
<includeonly>

Revision as of 23:22, 21 June 2012

Usage

This template can be used in templates that are used on pages with English language variants: articles in en-UK and articles in en-US. At the moment only UK and US English are recognised.

Article editor When using the template in an article, the editor can set its parameter |engvar=en-UK. The template text now will use the provided en-UK variant of words. This parameter setting is only needed once in thetemplate.

In the template So the template takes input parameter {{{engvar}}} Internally, the template has this construct:

...
| label= {{engvar| engvar={{{engvar}}} | en-uk=Football | en-us=Soccer }}
...

Depending on the engvar input, it returns oneofthevalues.

Notes
Language ids that are recognised are:

  1. In article code (article editor; case insensitive):
  • engval= en-UK, UK, en-uk, uk → returns the en-UK value
  • engval= en-US, US, en-us, us → returns the en-US value
  1. In template code (template editor):
  • Here, always use the lowercase language id: uk-en=Football (NOT uk-EN=Football)
  • Recognised language id's: en-uk=, uk=, en-us=, us=
  1. Unnamed parameters in template code can be used:
  • Unnamed parameter 1=pass throught the {{{engvar}}} variable. Named: engvar={{{engvar}}}
  • Unnamed parameter 2=en-UK definition
  • Unnamed parameter 3=en-US definition
<!-- The next three rows are equal in template code: -->
...
| label= {{engvar| engvar={{{engvar|}}} | en-uk=Football | en-us=Soccer }}
| label= {{engvar| 1={{{engvar|}}} | 2=Football | 3=Soccer }}
| label= {{engvar| 1={{{engvar|}}} | uk=Football | us=Soccer }}
...

Plain "en" variant

Default and plain "en"

  1. When the engvar=value from the article is not recognised, te

See also