Difference between revisions of "Template:Localize"

From Pathfinder Wiki
 
(28 intermediate revisions by 3 users not shown)
Line 1: Line 1:
<includeonly><nowiki/>{{#fornumargs: number
+
<includeonly>{{#vardefine:lang|{{#invoke:String|replace|{{{language|{{PAGELANGUAGE}}}}}|/||}}}}{{#iferror:{{#expr:{{{1}}}+0}}
| value
+
  |{{#vardefine:result|{{#cargo_query:tables=Localizations_{{{2|All}}}
| {{#vardefine:znum|{{#expr:{{#var:number}}-1}}}}
+
      |fields=text
{{#ifeq:{{#var:number}}|1|{{#vardefine:string|{{#lst:Localization:All{{GetLangSuffix}}|{{#var:value}}}}}}
+
      |where=id="{{{1}}}/{{#var:lang}}"
|{{#vardefine:string|{{#replace:{{#var:string}}|%{{#var:znum}}|{{#lst:Localization:All{{GetLangSuffix}}|{{#var:value}}}}}}}}}}
+
      |format=template
}}{{#var:string}}
+
      |template=LocalizeOutputQuery
</includeonly>
+
      |named args=yes
<noinclude>
+
      |default=}}
This template returns a localized version of a "canned" phrase that we use in the interfaces.  The phrase passed in is in English, but the output is in the language of the page that invokes it.  Therefore if we call the template from
+
  }}
<nowiki>[[</nowiki>some page]], we'd get the English version of the page, but if we call it from <nowiki>[[</nowiki>some page/es]], we would get the Spanish version of the phrase. 
+
  |{{#vardefine:result|{{{1}}}}}
 +
}}{{#if:{{#var:result}}
 +
  |{{#var:result}}
 +
  |{{#vardefine:localizationErrorCategories|{{#var:localizationErrorCategories}}[[Category:Missing Localization/{{{2|All}}}/{{{1|unsupplied}}}/{{#var:lang}}]]}}
 +
}}</includeonly><noinclude>
  
Here is an example:
+
This template returns a localized version of a "canned" phrase that we use in the interfaces. The phrase is in the language of the page that invokes it, so if we call the template from
<nowiki>{{</nowiki>{{FULLPAGENAME}}|The red rose}}<br/>
+
<nowiki>[[</nowiki>some page<nowiki>[[</nowiki>some page]], we'd get the English version of the page, but if we call it from <nowiki>[[</nowiki>some page/es]], we would get the Spanish version of the phrase.
  
{{{{FULLPAGENAME}}|The red rose}}
+
The template can also take a second argument to specify a different page in the Localization namespace. If omitted, the template defaults to searching [[:Localization:All]]. We may wish to use additional pages for things like honors, or the names of honor variants.
  
It is also possible to pass in numbered place-holders in the form of %''n'' where ''n'' is a number starting at 1. The arguments that follow will replace the placeholders:
+
If no localization can be found (unless the argument is a number), the invoking page is added to a Category:Missing_Localization/''page''/''key''/''language''. This category is saved in a variable called '''localizationErrorCategories'''. This variable can be printed to the page by calling the Template [[Template:PrintLocalizationErrors]] at the end of the page.
 +
In case of a missing localization the template will return an empty string, in other words, nothing.
  
<nowiki>{{</nowiki>{{FULLPAGENAME}}|The %1 rose<br/>
+
We don't throw an error on a numeric argument so that we can pass in a year - sometimes the year is a number, and sometimes it's "Unknown". We want to localize "Unknown" but pass the number through instead of returning a blank string.
|red<br/>
 
}}
 
  
{{{{FULLPAGENAME}}|The %1 rose|red}}
+
Here are some examples:
 +
<nowiki>{{</nowiki>Localize|2021}} &rarr; {{Localize|2021}}
  
 +
<nowiki>{{</nowiki>Localize|Answer Key}} &rarr; {{Localize|Answer Key}}
 +
 +
<nowiki>{{</nowiki>Localize|Lorem ipsum}} &rarr; {{Localize|Lorem ipsum}}
 +
 +
<nowiki>{{</nowiki>Localize|Switzerland|Countries|language=/es}} &rarr; {{Localize|Switzerland|Countries|language=/es}}
 +
 +
<nowiki>{{</nowiki>Localize|Switzerland|Countries|language=es}} &rarr; {{Localize|Switzerland|Countries|language=es}}
 +
 +
{{PrintLocalizationErrors}}
 +
 +
[[Category:Localization Templates]]
 
</noinclude>
 
</noinclude>

Latest revision as of 02:21, 1 August 2024


This template returns a localized version of a "canned" phrase that we use in the interfaces. The phrase is in the language of the page that invokes it, so if we call the template from [[some page[[some page]], we'd get the English version of the page, but if we call it from [[some page/es]], we would get the Spanish version of the phrase.

The template can also take a second argument to specify a different page in the Localization namespace. If omitted, the template defaults to searching Localization:All. We may wish to use additional pages for things like honors, or the names of honor variants.

If no localization can be found (unless the argument is a number), the invoking page is added to a Category:Missing_Localization/page/key/language. This category is saved in a variable called localizationErrorCategories. This variable can be printed to the page by calling the Template Template:PrintLocalizationErrors at the end of the page. In case of a missing localization the template will return an empty string, in other words, nothing.

We don't throw an error on a numeric argument so that we can pass in a year - sometimes the year is a number, and sometimes it's "Unknown". We want to localize "Unknown" but pass the number through instead of returning a blank string.

Here are some examples: {{Localize|2021}} → 2021

{{Localize|Answer Key}} →

Cannot access the database: :real_connect(): (08004/1040): Too many connections

{{Localize|Lorem ipsum}} →

Cannot access the database: :real_connect(): (08004/1040): Too many connections

{{Localize|Switzerland|Countries|language=/es}} → Suiza

{{Localize|Switzerland|Countries|language=es}} → Suiza