Template:Localized link: Difference between revisions

From Paraphilia+ Flags Wiki
m 1 revision imported
MediaWiki>Shirayuki
Marked this version for translation
Line 4: Line 4:
-->{{#ifeq:{{FULLPAGENAME:{{{1}}}}}|{{FULLPAGENAME:{{translatable}}}}<!--self link (including translation pages)-->
-->{{#ifeq:{{FULLPAGENAME:{{{1}}}}}|{{FULLPAGENAME:{{translatable}}}}<!--self link (including translation pages)-->
   |<b>
   |<b>
}}[[Special:MyLanguage/{{{1}}}|{{#if:{{{2|}}}|{{{2}}}|{{{2|{{#ifexist:Translations:{{#if:{{NAMESPACE:{{{1}}}}}|{{NAMESPACE:{{{1}}}}}:}}{{PAGENAME:{{{1}}}}}/Page display title/{{PAGELANGUAGE}}<!--if the source page, PAGELANGUAGE returns en-->
}}<!---->[[Special:MyLanguage/{{{1}}}|{{#if:{{{2|}}}
   |{{#if:{{{nsp|}}}
|{{{2}}}
     |{{PAGENAME:{{ {{TNTN|Translations:{{#if:{{NAMESPACE:{{{1}}}}}|{{NAMESPACE:{{{1}}}}}:}}{{PAGENAME:{{{1}}}}}/Page_display_title}} }} }}
|{{{2|{{#ifexist:Translations:{{#if:{{NAMESPACE:{{{1}}}}}|{{NAMESPACE:{{{1}}}}}:}}{{PAGENAME:{{{1}}}}}/Page display title/{{PAGELANGUAGE}}<!--if the source page, PAGELANGUAGE returns en-->
   |{{#ifexpr:{{#if:{{{nsp|}}}|1|0}} and {{NAMESPACENUMBER:{{{1}}}}}!=0
    |{{#ifeq:{{PAGELANGUAGE}}|en
      |{{PAGENAME:{{{1}}}}}
      |<!-- check whether the string is not empty --><!--
     -->{{#if:{{PAGENAME:{{ {{TNTN|Translations:{{#if:{{NAMESPACE:{{{1}}}}}|{{NAMESPACE:{{{1}}}}}:}}{{PAGENAME:{{{1}}}}}/Page_display_title}} }} }}
        |{{#ifeq:{{#invoke:string|find|{{PAGENAME:{{ {{TNTN|Translations:{{#if:{{NAMESPACE:{{{1}}}}}|{{NAMESPACE:{{{1}}}}}:}}{{PAGENAME:{{{1}}}}}/Page_display_title}} }} }}|:}}|0
          |{{PAGENAME:{{ {{TNTN|Translations:{{#if:{{NAMESPACE:{{{1}}}}}|{{NAMESPACE:{{{1}}}}}:}}{{PAGENAME:{{{1}}}}}/Page_display_title}} }} }}
          | {{#invoke:string|match|{{PAGENAME:{{ {{TNTN|Translations:{{#if:{{NAMESPACE:{{{1}}}}}|{{NAMESPACE:{{{1}}}}}:}}{{PAGENAME:{{{1}}}}}/Page_display_title}} }} }}|:(.*)}}
        }}
        |<!-- pass parameter to, e.g., "Template:LC zh"; check whether the string is not empty --><!--
      -->{{#if:{{ {{TNTN|Translations:{{#if:{{NAMESPACE:{{{1}}}}}|{{NAMESPACE:{{{1}}}}}:}}{{PAGENAME:{{{1}}}}}/Page_display_title}} | nsp = 0 }}
          |{{ {{TNTN|Translations:{{#if:{{NAMESPACE:{{{1}}}}}|{{NAMESPACE:{{{1}}}}}:}}{{PAGENAME:{{{1}}}}}/Page_display_title}} | nsp = 0 }}
          |{{{1}}}
        }}
      }}
    }}
     |{{ {{TNTN|Translations:{{#if:{{NAMESPACE:{{{1}}}}}|{{NAMESPACE:{{{1}}}}}:}}{{PAGENAME:{{{1}}}}}/Page_display_title}} }}
     |{{ {{TNTN|Translations:{{#if:{{NAMESPACE:{{{1}}}}}|{{NAMESPACE:{{{1}}}}}:}}{{PAGENAME:{{{1}}}}}/Page_display_title}} }}
   }}
   }}
   <!--if the translation page does not exist (or called from the source page), output as is-->
   <!--if the translation page does not exist (or called from the source page), output as is-->
   |{{#if:{{{nsp|}}}
   |{{#if:{{{nsp|}}}
     |{{PAGENAME:{{{1}}}}}
     |{{#if:{{PAGENAME:{{{1}}}}}
      |{{PAGENAME:{{{1}}}}}
      |{{{1}}}
    }}
     |{{{1}}}
     |{{{1}}}
   }}
   }}
}}}}}}}]]{{#ifeq:{{FULLPAGENAME:{{{1}}}}}|{{FULLPAGENAME:{{translatable}}}}<!--self link (including translation pages)-->
}}<!--#ifexist--><!--
-->}}}<!--{{{2|--><!--
-->}}<!--#if:{{{2|}}}--><!--
-->]]<!--
-->{{#ifeq:{{FULLPAGENAME:{{{1}}}}}|{{FULLPAGENAME:{{translatable}}}}<!--self link (including translation pages)-->
   |</b>
   |</b>
}}<span style="display:none">[[:{{{1}}}| ]]</span><!-- T63547 --><noinclude>
}}<span style="display:none">[[:{{{1}}}| ]]</span><!-- T63547 --><noinclude>
Line 38: Line 61:
<translate>
<translate>
<!--T:11-->
<!--T:11-->
If "<tvar name=1><code>nsp</code></tvar>" parameter is not defined, as link text displays the full pagename (including namespace); otherwise — if "<tvar name=1><code>nsp</code></tvar>" parameter is defined by any value link text displays the short pagename, without namespace.
If the "<tvar name=1><code>nsp</code></tvar>" parameter is not defined, as link text this displays the full pagename (including the namespace); otherwise — if the "<tvar name=1><code>nsp</code></tvar>" parameter is defined to any value the link text displays the short pagename (without the namespace).
 
<!--T:25-->
When linking to a section within a page, the section is not displayed in the link text.


=== Examples of simple usage === <!--T:3-->
=== Examples of simple usage === <!--T:3-->
Line 55: Line 81:
{{!}} {{Tlx|ll|Project:About}}
{{!}} {{Tlx|ll|Project:About}}
{{!}} {{ll|Project:About}}
{{!}} {{ll|Project:About}}
{{!}}-
{{!}} {{Tlx|ll|Project:About#See_also}}
{{!}} {{ll|Project:About#See_also}}
{{!}}-
{{!}}-
{{!}} {{Tlx|ll|Project:About|nsp{{=}}0}}
{{!}} {{Tlx|ll|Project:About|nsp{{=}}0}}
Line 67: Line 96:
</translate>
</translate>


# <translate><!--T:13--> Should better be substitute this template, and then the wikilink target embedded in a <tvar name=1>{{#tag:syntaxhighlight|{{^(}}tvar name=id{{)^}}...{{^(}}/tvar{{)^}}|lang=html|inline=1}}</tvar>, separately from the translatable displayed text of the link.</translate>
# <translate><!--T:13--> Substitute this template, then embed the wikilink target in a <tvar name=1>{{#tag:syntaxhighlight|{{^(}}tvar name=id{{)^}}...{{^(}}/tvar{{)^}}|lang=html|inline=1}}</tvar>, separate from the translatable text of the link.</translate>
#: <translate><!--T:22--> As example, instead <tvar name=1><code><nowiki>{{ll|Communication|About communication}}</nowiki></code></tvar>, translation markup in translatable page will be <tvar name=2>{{#tag:syntaxhighlight|[[{{^(}}tvar name=1{{)^}}Special:MyLanguage/Communication{{^(}}/tvar{{)^}}|About communication]]|lang=html|inline=1}}</tvar>.</translate>
#: <translate><!--T:26--> For example:</translate> {{#tag:syntaxhighlight|Learn more {{{{^(}}tvar name=1{{)^}}ll|Communication{{^(}}/tvar{{)^}}|about communication}}.|lang=html|inline=1}}
# <translate><!--T:14--> Alternatively, may be exclude this code from translatable section.</translate>
# <translate><!--T:16--> If link text is the same as the name of the target page, all of the code could also be embedded into <tvar name=1>{{tag|tvar|open}}</tvar>.</translate>
#: <translate><!--T:23--> As example, for <tvar name=1><code>some text <nowiki>{{ll|Communication|About communication}}</nowiki> some text</code></tvar>, translation markup in translatable page will be:</translate>
#: <translate><!--T:27--> For example:</translate> {{#tag:syntaxhighlight|Learn more about {{^(}}tvar name=1{{)^}}<nowiki>{{ll|Communication}}</nowiki>{{^(}}/tvar{{)^}}.|lang=html|inline=1}}
#: {{#tag:syntaxhighlight|{{^(}}translate{{)^}}some text{{^(}}/translate{{)^}} {{((}}ll{{!}}Communication{{!}}2={{^(}}translate{{)^}}About communication{{^(}}/translate{{)^}}{{))}} {{^(}}translate{{)^}}some text{{^(}}/translate{{)^}}|lang=html|inline=1}}
# <translate><!--T:28--> For standalone links, such as in a list or table, translate only the link text if it differs from the name of the target page.</translate> <translate><!--T:15--> This is useful for bulleted lists of links, e.g. in the "See also:" sections.</translate> <translate><!--T:29--> Make sure to include the parameter name when adding translate tags inside template syntax.</translate>
#: <translate><!--T:15--> This is useful for bulleted lists of links, e.g. in the "See also:" sections.</translate>
#: <translate><!--T:30--> For example:</translate>
# <translate><!--T:16--> If link text does not have to be different from the name of landing page, will be better to embed all this code into <tvar name=1>{{tag|tvar|open}}</tvar>.</translate>
::: {{#tag:syntaxhighlight|* {{((}}ll{{!}}Project:About{{))}}|lang=html|inline=1}}
#: <translate><!--T:24--> As example, instead <tvar name=1>{{Tlx|ll|Communication}}</tvar>, translation markup in translatable page will be <tvar name=2>{{#tag:syntaxhighlight|{{^(}}tvar name=1{{)^}}{{((}}ll{{!}}Communication{{))}}{{^(}}/tvar{{)^}}|lang=html|inline=1}}</tvar>.</translate>
::: {{#tag:syntaxhighlight|* {{((}}ll{{!}}Communication{{!}}2={{^(}}translate{{)^}}About communication{{^(}}/translate{{)^}}{{))}}|lang=html|inline=1}}
 
== Test cases ==
{{Localized link/testcases}}


<translate>
<translate>
Line 84: Line 116:
* {{tl|Page language link}} - <translate><!--T:20--> alias <tvar name=1>{{tl|pll}}</tvar></translate> - <translate><!--T:21--> add a link from a translatable page to another translatable page in the same language</translate>
* {{tl|Page language link}} - <translate><!--T:20--> alias <tvar name=1>{{tl|pll}}</tvar></translate> - <translate><!--T:21--> add a link from a translatable page to another translatable page in the same language</translate>
}}
}}
[[Category:Internationalization templates]]
[[Category:Internationalization templates{{#translation:}}]]
</noinclude>
</noinclude>

Revision as of 03:07, 3 July 2025

<languages/> [[Special:MyLanguage/{{{1}}}|{{{1}}}]][[:{{{1}}}| ]]

Template documentation

Template:Tsh Template:High-use

<translate>

Purpose

</translate> <translate> This helper template can be used to link to [[<tvar name=1>Special:LanguageStats</tvar>|translatable pages]] in the user's language.</translate> <translate> It uses the special page prefix <tvar name=1>Special:MyLanguage/</tvar>, which checks if there is a translated version of a page in the user's language, and links to it if there is one, and links to a fallback language where available, or the default wiki language version (English in MediaWiki) if there isn't.</translate>

<translate> It should be used in translated pages, so that they link to the right page even if there is no translated page in that language.

Usage

</translate> Template:Localized link/doc

<translate> If the "<tvar name=1>nsp</tvar>" parameter is not defined, as link text this displays the full pagename (including the namespace); otherwise — if the "<tvar name=1>nsp</tvar>" parameter is defined to any value the link text displays the short pagename (without the namespace).

When linking to a section within a page, the section is not displayed in the link text.

Examples of simple usage

</translate> Template:(| class="wikitable" |- ! <translate> Use</translate> ! <translate> Becomes</translate> |- | Template:Tlx | Communication |- | Template:Tlx | コミュニケーション |- | Template:Tlx | Project:About |- | Template:Tlx | Project:About#See_also |- | Template:Tlx | About |Template:)

<translate>

Usage in translatable pages

On pages prepared for translation with the <tvar name=1>Extension:Translate </tvar> extension, this template may be used in three ways. </translate>

  1. <translate> Substitute this template, then embed the wikilink target in a <tvar name=1>[[:Template:^(]]tvar name=id[[:Template:)^]]...[[:Template:^(]]/tvar[[:Template:)^]]</tvar>, separate from the translatable text of the link.</translate>
    <translate> For example:</translate> Learn more {{[[:Template:^(]]tvar name=1[[:Template:)^]]ll|Communication[[:Template:^(]]/tvar[[:Template:)^]]|about communication}}.
  2. <translate> If link text is the same as the name of the target page, all of the code could also be embedded into <tvar name=1>Template:Tag</tvar>.</translate>
    <translate> For example:</translate> Learn more about [[:Template:^(]]tvar name=1[[:Template:)^]]{{ll|Communication}}[[:Template:^(]]/tvar[[:Template:)^]].
  3. <translate> For standalone links, such as in a list or table, translate only the link text if it differs from the name of the target page.</translate> <translate> This is useful for bulleted lists of links, e.g. in the "See also:" sections.</translate> <translate> Make sure to include the parameter name when adding translate tags inside template syntax.</translate>
    <translate> For example:</translate>
* {{ll|Project:About}}
* {{ll|Communication|2=[[:Template:^(]]translate[[:Template:)^]]About communication[[:Template:^(]]/translate[[:Template:)^]]}}

Test cases

Template:Localized link/testcases

<translate>

See also

</translate>

[[Category:Template documentation pages{{#translation:}}]]

[[Category:Internationalization templates{{#translation:}}]]