Template:Localization/doc

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
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 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
Namespace.
 * Parameter 1

Key.
 * Parameter 2

Language. This can be used to display the stored value of a specific language. By default, this is what lang returns.
 * Parameter 3 (optional)

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:
 * All named parameters prefixed with

A:

B:

C:

Result:

Register localization info
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
Use in the same template. Make sure to place it before any l10n call, ideally at the very top of the code.

Autoload
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  when needed. For example, for foo, l10n will try to transclude.

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

Example
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.

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.  (which would return   on the English wiki and   on the Italian wiki). See the source code of Template:Hint for details regarding this example.