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)))
 
(6 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
<includeonly><!--
 
<includeonly><!--
-->{{#ifeq: {{#language:{{lc:{{#explode:{{SUBPAGENAME:{{{1|{{SUBPAGENAME}}}}}}}|{{#ifeq:{{NAMESPACE:{{{1|{{SUBPAGENAME}}}}}|{{ns:6}}| |:}}|0}}}}}}
+
 
     | {{lc:{{#explode:{{SUBPAGENAME:{{{1|{{SUBPAGENAME}}}}}}}|{{#ifeq:{{NAMESPACE:{{{1|{{SUBPAGENAME}}}}}|{{ns:6}}| |:}}|0}}}}
+
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
     | {{#ifeq: {{#language:{{lc:{{#explode:{{PAGENAME:{{{1|{{PAGENAME}}}}}}}|{{#ifeq:{{NAMESPACE:{{{1|{{PAGENAME}}}}}|{{ns:6}}| |:}}|0}}}}}}
+
 
         | {{lc:{{#explode:{{PAGENAME:{{{1|{{PAGENAME}}}}}}}|{{#ifeq:{{NAMESPACE:{{{1|{{PAGENAME}}}}}|{{ns:6}}| |:}}|0}}}}
+
if the code in this template is changed to verify all subpages the code in [[Template:Sort key of page]] must be adapted also
         |<!-- return nothing
+
 
       -->| {{lc:{{#explode:{{PAGENAME:{{{1|{{PAGENAME}}}}}}}|{{#ifeq:{{NAMESPACE:{{{1|{{PAGENAME}}}}}|{{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}}}}
 +
     | {{#ifeq: {{#language:{{lc:{{#explode:{{PAGENAME:{{{1|{{FULLPAGENAME}}}}}}}|{{#ifeq:{{NAMESPACE:{{{1|{{FULLPAGENAME}}}}}}}|{{ns:6}}| |:}}|0}}}}}}
 +
         | {{lc:{{#explode:{{PAGENAME:{{{1|{{FULLPAGENAME}}}}}}}|{{#ifeq:{{NAMESPACE:{{{1|{{FULLPAGENAME}}}}}}}|{{ns:6}}| |:}}|0}}}}
 +
         | {{CONTENTLANGUAGE}}<!--
 +
       -->| {{lc:{{#explode:{{PAGENAME:{{{1|{{FULLPAGENAME}}}}}}}|{{#ifeq:{{NAMESPACE:{{{1|{{FULLPAGENAME}}}}}}}|{{ns:6}}| |:}}|0}}}}<!--
 
     -->}}<!--
 
     -->}}<!--
   -->| {{lc:{{#explode:{{SUBPAGENAME:{{{1|{{SUBPAGENAME}}}}}}}|{{#ifeq:{{NAMESPACE:{{{1|{{SUBPAGENAME}}}}}|{{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. 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.
+
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==

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