From Terraria Wiki
(Redirected from Template:L10n)
Jump to: navigation, search
Lua logo.svg
This template uses Module:Localization, a script written in the Lua programming language. Please see wikipedia:Lua and mw:Extension:Scribunto to learn more about Lua.
Template-info.svg Documentation The documentation below is transcluded from Template:Localization/doc. (edit | history)

This template is used to dynamically display predefined text (which is stored via {{localization/register}}), mainly within templates, depending on the Terraria language wiki it is used on. It is the core template of the effort of standardizing template code across language wikis and preventing outdated templates. See Help:I18n & l10n for Templates for more information.

Use {{l10n}} as a shortcut.

Basic concept[edit source]

In a template, all English texts and other language-specific strings (e.g. category names) are stored in an "l10n database" at the top of the template, i.e. their inline mentions are replaced by a variable pointing to their database entry in the l10n database. This facilitates storing translations of one string in the database and choosing between them upon template call, depending on the wiki's language.

The database is set up using {{l10n/register}}. It assigns every string a unique two-level identifier consisting of namespace (Note that this is not related to the MediaWiki Namespace concept.) and key. The namespace is usually the template's name and the key a descriptive "name" of the string.

Upon retrieving the stored strings (which is done using this template), their namespace and key have to be specified. The differentiation between which translation to choose is handled by {{lang}}, which determines the wiki's language automatically. If there is no string available for the specified namespace–key combination in the respective language, the English version will be used.

Usage[edit source]

{{ l10n | <namespace> | <key> | <lang> (optional) }}</nowiki>

Parameter 1


Parameter 2


Parameter 3 (optional)

Language. This can be used to display the stored value of a specific language. By default, this is what {{lang}} returns.

All named parameters prefixed with $

Placeholders for formatting. They will be replaced in the output by a string that is the same for every language. Placeholders can also be defined recursively. See the following example:

|abc=input: $x
|t = zzz
A: {{l10n|test|abc|$x=xyz}}

B: {{l10n|test|mn|$d=kkkk|$f=jjjj}}

C: {{l10n|test|abc|$x={{l10n|test|mn|$d=x|$f=y}} }}


A: input: xyz

B: abckkkkejjjjg

C: input: abcxeyg

Register localization info[edit source]

The l10n database is declared by {{l10n/register}}. It is possible to either have it load automatically or register it manually. In the end, both methods require a manual definition of the database – the only difference is that with autoload, this is not done in the template source code itself but in a separate template.

Manual registration[edit source]

Use in the same template. Make sure to place it before any {{l10n}} call, ideally at the very top of the code.

Autoload[edit source]

Since the database is only setting variables, it is not mandatory to include it in the same template. Instead, it can be moved to a separate subtemplate which is then transcluded at the beginning of the base template. {{l10n}} has a functionality that will try to automatically transclude ("autoload") such an outsourced l10n database by transcluding Template:<namespace>/l10n when needed. For example, for {{l10n|foo|bar}}, {{l10n}} will try to transclude Template:foo/l10n.

This way is recommended because it reduces the number of {{l10n/register}} transclusions and improves performance.

Example[edit source]

Take Template:Hint as an example:

Register localization info (the l10n database) first. This can be done either in Template:Hint/l10n (for the autoload method) or at the top of Template:Hint itself.

//en version
	-->|default=No hint provided.<!-- 
//it version
	-->|default=Nessun suggerimento fornito.<!-- 
... more languages if needed.

Simply add more languages in the same manner if needed. Make sure to keep the alphabetical order of the language codes, with English always at the top.

Then, in the template code, use {{l10n}} to retrieve a string for the current language from the l10n database, e.g. {{l10n|hint|hint}} (which would return Hint: on the English wiki and Suggerimento: on the Italian wiki). See the source code of {{hint}} for details regarding this example.

Resulting output:

Code Result
Hint: No hint provided.
<!-- manually set language to IT -->
Now gets the Italian version:

Now gets the Italian version:

Suggerimento: Nessun suggerimento fornito.