「テンプレート:LangSwitch」の版間の差分

提供: 脳科学辞典
移動先: 案内検索
(ページの作成:「<!-- Documentation of code Snippet: 1) "{{#if:{{{lang|}}}|{{{lang}}}|{{int:Lang}}}}" - is the chosen language, either set by parameter "lang=xx" or by language of t...」)
 
(langSwitchFromWiki -> langSwitch)
1行目: 1行目:
<!-- Documentation of code Snippet:
+
<includeonly>{{#invoke: fallback|langSwitch}}</includeonly><noinclude>
1) "{{#if:{{{lang|}}}|{{{lang}}}|{{int:Lang}}}}" - is the chosen language, either set by parameter "lang=xx"
 
    or by language of the user "{{int:Lang}}"
 
2) "{{{ {{#if:{{{lang|}}}|{{{lang}}}|{{int:Lang}}}} |}}}" - is the input parameter matching the language for example {{{xx|}}}
 
3) Without the fallback templates the LangSwitch template would be
 
{{{
 
{{#switch: {{{ {{#if:{{{lang|}}}|{{{lang}}}|{{int:Lang}}}} |}}} // switch based on input parameter matching the language ie. xx
 
  | ~        = empty                                    // if |xx=~| than the template will return {{{empty}}} which is empty
 
  |          = {{#if: {{{default|}}} | default | en }}  // if xx is undefined or empty |xx=| than return {{{default}}} or {{{en}}}
 
  | #default = {{#if:{{{lang|}}}|{{{lang}}}|{{int:Lang}}}} // for all other cases return {{{xx|}}}
 
}}
 
|}}}
 
 
 
The actual template is bit more complicated calling templates {{GetFallback}} and {{GetFallback2}} to allow language fallback. For example if desired encoding is "sr-ec" (Serbian using Cyrillic alphabet) than the fall back would be "sr" (Serbian))
 
-->{{{
 
  {{#switch: {{{ {{#if:{{{lang|}}}|{{{lang}}}|{{int:Lang}}}} |}}}
 
  | ~ = empty
 
  |  = {{#switch: {{{ {{GetFallback| {{#if:{{{lang|}}}|{{{lang}}}|{{int:Lang}}}} |default=default}} |}}}
 
    | ~ = empty
 
    |  = {{#switch: {{{ {{GetFallback2| {{#if:{{{lang|}}}|{{{lang}}}|{{int:Lang}}}} |default=default}} |}}}
 
      | ~        = empty
 
      |          = {{#if: {{{default|}}} | default | en }}
 
      | #default = {{GetFallback2| {{#if:{{{lang|}}}|{{{lang}}}|{{int:Lang}}}} |default=default}}
 
      }}
 
    | #default = {{GetFallback| {{#if:{{{lang|}}}|{{{lang}}}|{{int:Lang}}}} |default=default}}
 
    }}
 
  | #default = {{#if:{{{lang|}}}|{{{lang}}}|{{int:Lang}}}}
 
  }}
 
|}}}<includeonly>{{#ifeq:{{NAMESPACE}}|File||{{#if:{{{en|}}}{{{default|}}}{{{nocat|<noinclude>1</noinclude>}}}||[[Category:LangSwitch template without English version]]}}}}</includeonly><noinclude>
 
 
 
 
{{Documentation}}
 
{{Documentation}}
  
 
</noinclude>
 
</noinclude>

2013年12月11日 (水) 05:29時点における版

[create] Documentation icon Template documentation