Difference between revisions of "Template:Language code of page"

From Creative Commons
Jump to: navigation, search
m (Protected "Template:Language code of page": Widely used template ([edit=sysop] (indefinite) [move=sysop] (indefinite)))
 
(18 intermediate revisions by the same user not shown)
Line 1: Line 1:
<includeonly>
+
<includeonly><!--
----
 
{{{1|}}}
 
----
 
{{SUBPAGENAME{{#if:{{{1|}}}|{{colon}}{{{1}}}|}}}}
 
----
 
  
 +
currently we only check the SUBPAGENAME and the PAGENAME of pages to discover their language - if sub-sub-sub...pages are used, it might fail
  
<!--
+
if the code in this template is changed to verify all subpages the code in [[Template:Sort key of page]] must be adapted also
-->{{#ifeq: {{#language:{{lc:{{#explode:{{SUBPAGENAME
+
 
{{#if:{{{1|}}}|{{colon}}{{{1}}}|}}
+
-->{{#ifeq: {{#language:{{lc:{{#explode:{{SUBPAGENAME:{{{1|{{FULLPAGENAME}}}}}}}|{{#ifeq:{{NAMESPACE:{{{1|{{FULLPAGENAME}}}}}}}|{{ns:6}}| |:}}|0}}}}}}
}}|{{Language delimiter}}|0}}}}}}
+
     | {{lc:{{#explode:{{SUBPAGENAME:{{{1|{{FULLPAGENAME}}}}}}}|{{#ifeq:{{NAMESPACE:{{{1|{{FULLPAGENAME}}}}}}}|{{ns:6}}| |:}}|0}}}}
     | {{lc:{{#explode:{{SUBPAGENAME{{#if:{{{1|}}}|{{colon}}{{{1}}}|}}}}|{{Language delimiter}}|0}}}}
+
     | {{#ifeq: {{#language:{{lc:{{#explode:{{PAGENAME:{{{1|{{FULLPAGENAME}}}}}}}|{{#ifeq:{{NAMESPACE:{{{1|{{FULLPAGENAME}}}}}}}|{{ns:6}}| |:}}|0}}}}}}
     | {{#language:{{lc:{{#explode:{{SUBPAGENAME{{#if:{{{1|}}}|{{colon}}{{{1}}}|}}|{{Language delimiter}}|0}}}}}} -- {{lc:{{#explode:{{SUBPAGENAME{{#if:{{{1|}}}|{{colon}}{{{1}}}|}}}}|{{Language delimiter}}|0}}}}
+
        | {{lc:{{#explode:{{PAGENAME:{{{1|{{FULLPAGENAME}}}}}}}|{{#ifeq:{{NAMESPACE:{{{1|{{FULLPAGENAME}}}}}}}|{{ns:6}}| |:}}|0}}}}
    | different<!--
+
        | {{CONTENTLANGUAGE}}<!--
 +
      -->| {{lc:{{#explode:{{PAGENAME:{{{1|{{FULLPAGENAME}}}}}}}|{{#ifeq:{{NAMESPACE:{{{1|{{FULLPAGENAME}}}}}}}|{{ns:6}}| |:}}|0}}}}<!--
 +
    -->}}<!--
 +
  -->| {{lc:{{#explode:{{SUBPAGENAME:{{{1|{{FULLPAGENAME}}}}}}}|{{#ifeq:{{NAMESPACE:{{{1|{{FULLPAGENAME}}}}}}}|{{ns:6}}| |:}}|0}}}}<!--
 
-->}}</includeonly><noinclude>
 
-->}}</includeonly><noinclude>
Template '''{{PAGENAME}}''' returns the language code of a page. If no page name is passed in as the first parameter, the current page (in which it is being used) applies. If there is no language code, it returns empty.
+
Template '''{{PAGENAME}}''' returns the language code of a page. The language code is retrieved from the page name passed in as first parameter. If no page name is passed in as the first parameter, the name of the current page (where the template it is being used) applies. If there is no language code in the name, it returns the language code of the wiki's content language.
 +
 
 +
This is a support template, and should not be used on normal content pages. It is used by [[Template:Assign property Has language]] and [[Template:Translated From/code]].
  
 
==Use==
 
==Use==
Line 24: Line 25:
 
==Examples==
 
==Examples==
 
===No page parameter===
 
===No page parameter===
If no first parameter is passed in, the current page applies.
+
If no first parameter is passed in, the current page applies. This page has no language code, so nothing is returned.
 
<pre>
 
<pre>
 
{{Language code of page}}
 
{{Language code of page}}
Line 35: Line 36:
 
</pre>
 
</pre>
 
{{Language code of page|Pt:Página principal}}
 
{{Language code of page|Pt:Página principal}}
 +
 +
<pre>
 +
{{Language code of page|De:Hauptseite}}
 +
</pre>
 +
{{Language code of page|De:Hauptseite}}
 +
 +
<pre>
 +
{{Language code of page|Ar:مشاركة الأعمال الإبداعية 22}}
 +
</pre>
 +
{{Language code of page|Ar:مشاركة الأعمال الإبداعية 22}}
 +
 +
Notice that the language code is searched firstly in the subpage name, and, if none is found, then searched in the pagename:
 +
<pre>
 +
{{Language code of page|Case Studies/De:Breipott}}
 +
</pre>
 +
{{Language code of page|Case Studies/De:Breipott}}
 +
 +
<pre>
 +
{{Language code of page|Ja:Flickr/Publish}}
 +
</pre>
 +
{{Language code of page|Ja:Flickr/Publish}}
 +
 +
In particular, the language code in the subpage name has precedence:
 +
<pre>
 +
{{Language code of page|Ja:Flickr/Pt:Publish}}
 +
</pre>
 +
{{Language code of page|Ja:Flickr/Pt:Publish}}
  
 
===Page without a language code===
 
===Page without a language code===
If no first parameter is passed in, the current page applies.
+
If a page parameter is passed in, but the page does not have a language code, nothing is returned (tested using this very page).
 
<pre>
 
<pre>
 
{{Language code of page|Template:Language code of page}}
 
{{Language code of page|Template:Language code of page}}
Line 43: Line 71:
 
{{Language code of page|Template:Language code of page}}
 
{{Language code of page|Template:Language code of page}}
  
[[Category:Translation templates|{{PAGENAME}}]]
+
===Category namespace===
 +
<pre>
 +
{{Language code of page|Category:Ksh:Övversäzongsprojäk}}
 +
</pre>
 +
{{Language code of page|Category:Ksh:Övversäzongsprojäk}}
 +
 
 +
===File namespace===
 +
<pre>
 +
{{Language code of page|File:Pt Casos de estudo.png}}
 +
</pre>
 +
{{Language code of page|File:Pt Casos de estudo.png}}
 +
 
 +
[[Category:Support translation templates|{{PAGENAME}}]]
 
</noinclude>
 
</noinclude>

Latest revision as of 15:26, 29 April 2011

Template Language code of page returns the language code of a page. The language code is retrieved from the page name passed in as first parameter. If no page name is passed in as the first parameter, the name of the current page (where the template it is being used) applies. If there is no language code in the name, it returns the language code of the wiki's content language.

This is a support template, and should not be used on normal content pages. It is used by Template:Assign property Has language and Template:Translated From/code.

Use

{{Language code of page|optional page name}}

Examples

No page parameter

If no first parameter is passed in, the current page applies. This page has no language code, so nothing is returned.

{{Language code of page}}

{{#ifeq: {{#explode:language code of page|{{#ifeq:template|file| |:}}|0}}

    | {{#explode:language code of page|{{#ifeq:template|file| |:}}|0}}
    | {{#ifeq: {{#explode:language code of page|{{#ifeq:template|file| |:}}|0}}
        | {{#explode:language code of page|{{#ifeq:template|file| |:}}|0}}
        | en| {{#explode:language code of page|{{#ifeq:template|file| |:}}|0}}}}| {{#explode:language code of page|{{#ifeq:template|file| |:}}|0}}}}

Page with a language code

{{Language code of page|Pt:Página principal}}

{{#ifeq: {{#explode:pt:página principal|{{#ifeq:|file| |:}}|0}}

    | {{#explode:pt:página principal|{{#ifeq:|file| |:}}|0}}
    | {{#ifeq: {{#explode:pt:página principal|{{#ifeq:|file| |:}}|0}}
        | {{#explode:pt:página principal|{{#ifeq:|file| |:}}|0}}
        | en| {{#explode:pt:página principal|{{#ifeq:|file| |:}}|0}}}}| {{#explode:pt:página principal|{{#ifeq:|file| |:}}|0}}}}
{{Language code of page|De:Hauptseite}}

{{#ifeq: {{#explode:de:hauptseite|{{#ifeq:|file| |:}}|0}}

    | {{#explode:de:hauptseite|{{#ifeq:|file| |:}}|0}}
    | {{#ifeq: {{#explode:de:hauptseite|{{#ifeq:|file| |:}}|0}}
        | {{#explode:de:hauptseite|{{#ifeq:|file| |:}}|0}}
        | en| {{#explode:de:hauptseite|{{#ifeq:|file| |:}}|0}}}}| {{#explode:de:hauptseite|{{#ifeq:|file| |:}}|0}}}}
{{Language code of page|Ar:مشاركة الأعمال الإبداعية 22}}

{{#ifeq: {{#explode:ar:مشاركة الأعمال الإبداعية 22|{{#ifeq:|file| |:}}|0}}

    | {{#explode:ar:مشاركة الأعمال الإبداعية 22|{{#ifeq:|file| |:}}|0}}
    | {{#ifeq: {{#explode:ar:مشاركة الأعمال الإبداعية 22|{{#ifeq:|file| |:}}|0}}
        | {{#explode:ar:مشاركة الأعمال الإبداعية 22|{{#ifeq:|file| |:}}|0}}
        | en| {{#explode:ar:مشاركة الأعمال الإبداعية 22|{{#ifeq:|file| |:}}|0}}}}| {{#explode:ar:مشاركة الأعمال الإبداعية 22|{{#ifeq:|file| |:}}|0}}}}

Notice that the language code is searched firstly in the subpage name, and, if none is found, then searched in the pagename:

{{Language code of page|Case Studies/De:Breipott}}

{{#ifeq: {{#explode:case studies/de:breipott|{{#ifeq:|file| |:}}|0}}

    | {{#explode:case studies/de:breipott|{{#ifeq:|file| |:}}|0}}
    | {{#ifeq: {{#explode:case studies/de:breipott|{{#ifeq:|file| |:}}|0}}
        | {{#explode:case studies/de:breipott|{{#ifeq:|file| |:}}|0}}
        | en| {{#explode:case studies/de:breipott|{{#ifeq:|file| |:}}|0}}}}| {{#explode:case studies/de:breipott|{{#ifeq:|file| |:}}|0}}}}
{{Language code of page|Ja:Flickr/Publish}}

{{#ifeq: {{#explode:ja:flickr/publish|{{#ifeq:|file| |:}}|0}}

    | {{#explode:ja:flickr/publish|{{#ifeq:|file| |:}}|0}}
    | {{#ifeq: {{#explode:ja:flickr/publish|{{#ifeq:|file| |:}}|0}}
        | {{#explode:ja:flickr/publish|{{#ifeq:|file| |:}}|0}}
        | en| {{#explode:ja:flickr/publish|{{#ifeq:|file| |:}}|0}}}}| {{#explode:ja:flickr/publish|{{#ifeq:|file| |:}}|0}}}}

In particular, the language code in the subpage name has precedence:

{{Language code of page|Ja:Flickr/Pt:Publish}}

{{#ifeq: {{#explode:ja:flickr/pt:publish|{{#ifeq:|file| |:}}|0}}

    | {{#explode:ja:flickr/pt:publish|{{#ifeq:|file| |:}}|0}}
    | {{#ifeq: {{#explode:ja:flickr/pt:publish|{{#ifeq:|file| |:}}|0}}
        | {{#explode:ja:flickr/pt:publish|{{#ifeq:|file| |:}}|0}}
        | en| {{#explode:ja:flickr/pt:publish|{{#ifeq:|file| |:}}|0}}}}| {{#explode:ja:flickr/pt:publish|{{#ifeq:|file| |:}}|0}}}}

Page without a language code

If a page parameter is passed in, but the page does not have a language code, nothing is returned (tested using this very page).

{{Language code of page|Template:Language code of page}}

{{#ifeq: {{#explode:language code of page|{{#ifeq:template|file| |:}}|0}}

    | {{#explode:language code of page|{{#ifeq:template|file| |:}}|0}}
    | {{#ifeq: {{#explode:language code of page|{{#ifeq:template|file| |:}}|0}}
        | {{#explode:language code of page|{{#ifeq:template|file| |:}}|0}}
        | en| {{#explode:language code of page|{{#ifeq:template|file| |:}}|0}}}}| {{#explode:language code of page|{{#ifeq:template|file| |:}}|0}}}}

Category namespace

{{Language code of page|Category:Ksh:Övversäzongsprojäk}}

{{#ifeq: {{#explode:ksh:övversäzongsprojäk|{{#ifeq:category|file| |:}}|0}}

    | {{#explode:ksh:övversäzongsprojäk|{{#ifeq:category|file| |:}}|0}}
    | {{#ifeq: {{#explode:ksh:övversäzongsprojäk|{{#ifeq:category|file| |:}}|0}}
        | {{#explode:ksh:övversäzongsprojäk|{{#ifeq:category|file| |:}}|0}}
        | en| {{#explode:ksh:övversäzongsprojäk|{{#ifeq:category|file| |:}}|0}}}}| {{#explode:ksh:övversäzongsprojäk|{{#ifeq:category|file| |:}}|0}}}}

File namespace

{{Language code of page|File:Pt Casos de estudo.png}}

{{#ifeq: {{#explode:pt casos de estudo.png|{{#ifeq:file|file| |:}}|0}}

    | {{#explode:pt casos de estudo.png|{{#ifeq:file|file| |:}}|0}}
    | {{#ifeq: {{#explode:pt casos de estudo.png|{{#ifeq:file|file| |:}}|0}}
        | {{#explode:pt casos de estudo.png|{{#ifeq:file|file| |:}}|0}}
        | en| {{#explode:pt casos de estudo.png|{{#ifeq:file|file| |:}}|0}}}}| {{#explode:pt casos de estudo.png|{{#ifeq:file|file| |:}}|0}}}}