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

From Creative Commons
Jump to: navigation, search
Line 1: Line 1:
 
<includeonly><!--
 
<includeonly><!--
 +
 +
the code in this template must closely resemble (in nature) the one in [[Template:Assign property Has language]], so keep close tabs on changes to the main algorithm of both
 +
 
-->{{#ifeq: {{#language:{{lc:{{#explode:{{SUBPAGENAME:{{{1|{{FULLPAGENAME}}}}}}}|{{#ifeq:{{NAMESPACE:{{{1|{{FULLPAGENAME}}}}}}}|{{ns:6}}| |:}}|0}}}}}}
 
-->{{#ifeq: {{#language:{{lc:{{#explode:{{SUBPAGENAME:{{{1|{{FULLPAGENAME}}}}}}}|{{#ifeq:{{NAMESPACE:{{{1|{{FULLPAGENAME}}}}}}}|{{ns:6}}| |:}}|0}}}}}}
 
     | {{lc:{{#explode:{{SUBPAGENAME:{{{1|{{FULLPAGENAME}}}}}}}|{{#ifeq:{{NAMESPACE:{{{1|{{FULLPAGENAME}}}}}}}|{{ns:6}}| |:}}|0}}}}
 
     | {{lc:{{#explode:{{SUBPAGENAME:{{{1|{{FULLPAGENAME}}}}}}}|{{#ifeq:{{NAMESPACE:{{{1|{{FULLPAGENAME}}}}}}}|{{ns:6}}| |:}}|0}}}}

Revision as of 03:59, 27 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 empty.

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