Difference between revisions of "Template:Localize"
DesignerThan (talk | contribs) |
DesignerThan (talk | contribs) |
||
Line 1: | Line 1: | ||
− | <includeonly><nowiki/>{{#vardefine: | + | <includeonly><nowiki/>{{#vardefine:lang|{{PAGELANGUAGE}}}}{{#iferror:{{#expr:{{{1}}}+0}} |
+ | |{{#vardefine:result|{{#cargo_query:tables=Localizations_{{{2|All}}}|fields=text|where=id="{{{1}}}/{{#var:lang}}"|default=}}}} | ||
+ | |{{#vardefine:result|{{{1}}}}} | ||
+ | }}{{#if:{{#var:result}} | ||
+ | |{{#var:result}}{{#cargo_store:_table=UsageOfLocalizations|lang={{#var:lang}}|id={{{1}}}/{{#var:lang}}|locPage={{{2|All}}}|lang={{#var:lang}}}} | ||
+ | |{{#vardefine:localizationErrorCategories|{{#var:localizationErrorCategories}}[[Category:Missing Localization/{{{2|All}}}/{{{1|unsupplied}}}/{{#var:lang}}]]}} | ||
+ | }}</includeonly><noinclude> | ||
+ | {{#cargo_declare:_table=UsageOfLocalizations | ||
+ | |id=String (mandatory) | ||
+ | |locPage=String (mandatory) | ||
+ | |lang=String (mandatory) | ||
+ | }} | ||
+ | |||
+ | |||
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 | 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>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. | <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. | ||
Line 5: | Line 18: | ||
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. | 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 | + | 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. | 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. | 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 | + | Here are some examples: |
− | <nowiki>{{</nowiki> | + | <nowiki>{{</nowiki>Localize2|2021}} → {{Localize2|2021}} |
− | <nowiki>{{</nowiki> | + | <nowiki>{{</nowiki>Localize2|Answer Key}} → {{Localize2|Answer Key}} |
− | <nowiki>{{</nowiki> | + | <nowiki>{{</nowiki>Localize2|Lorem ipsum}} → {{Localize2|Lorem ipsum}} |
− | <nowiki>{{</nowiki> | + | <nowiki>{{</nowiki>Localize2|Switzerland|Countries}} → {{Localize2|Switzerland|Countries}} |
{{PrintLocalizationErrors}} | {{PrintLocalizationErrors}} | ||
+ | |||
+ | [[Category:Localization Templates]] | ||
</noinclude> | </noinclude> |
Revision as of 02:50, 30 January 2022
This template defines the table "UsageOfLocalizations". View table.
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: {{Localize2|2021}} → Template:Localize2
{{Localize2|Answer Key}} → Template:Localize2
{{Localize2|Lorem ipsum}} → Template:Localize2
{{Localize2|Switzerland|Countries}} → Template:Localize2