Help:I18n & l10n for templates

From Terraria Wiki
Jump to navigation Jump to search

On the Terraria Wikis, a template is i18n-ready (i.e., prepared for internationalization – i18n – and localization – l10n) if its code can be shared between different languages without requiring to create a separate template for each language. This is achieved by splitting the functionality and the messages of the template – the functionality is always the same, but the messages are translated, if necessary, based on their translations stored within the code.

This system greatly simplifies the process of maintaining templates across numerous language variants' wikis. All i18n-ready templates can be found here: Category:I18n-ready templates.

The Terraria Wikis use the official ISO 639-1 codes (see full list) to refer to languages, or ISO 639-3 (see full list) if no ISO 639-1 code exists.

Preparation

For any specific target language, some preparation is required to get it working properly with the i18n system of the Terraria Wikis.

For languages with a separate wiki

If the target language has its own wiki subdomain,[a] the following steps are to be taken:

  • Port {{lang}} to the target language's wiki. Refer to the de and zh versions for examples. (Template:Lang: de, fr, hu, ru, pl, pt, uk, zh, es-formal)
  • Port {{l10n}} and {{l10n/register}} to the target language's wiki. This is as simple as copying the code of the English version. (Template:L10n: de, fr, hu, ru, pl, pt, uk, zh, es-formal)
  • Port {{tr}} to the target language's wiki. Refer to the de and zh versions for examples. If you still don't know how to set it up, simply put {{{1|}}} as the content of the template. This makes it a dummy template, behaving similar to the English version. (Template:Tr: de, fr, hu, ru, pl, pt, uk, zh, es-formal)

For languages without a separate wiki

If the target language does not have its own wiki subdomain and instead exists within the English wiki on language subpages,[b] the following steps are to be taken:

  • Initialize the translation database of the target language: Create and/or fill Module:Tr/db-<language code>, (e.g. Module:Tr/db-fr for French). Refer to the es, it, and cs versions for examples. You can copy the empty English module and use it as a framework for the future translation database.
  • Create Module:Tr/db-<language code> with the following content: return require('Module:Tr/loaddata').load('<language code>').

Translation databases

  • Localization

    Once this preparation work has been successfully completed and the foundation for internationalization and localization of the target language has been laid, any i18n-ready template can now be localized to the target language. In order to do so, the following steps are to be taken, taking Chinese localization of {{achievement}} as an example:

    Locate the localization section (usually at the very top of the code). At least the English messages are always already stored there. For {{achievement}}, we can see the en and fr l10n information:

    <!-- register localization info: -->
    {{l10n/register|achievement|en
    |link=Achievements
    |cate=Achievement-related elements
    }}
    <!-- fr version -->
    {{l10n/register|achievement|fr
    |link=Succès
    |cate=Éléments relatifs aux succès
    }}

    Now, add the translated Chinese messages:

    <!-- register localization info: -->
    {{l10n/register|achievement|en
    |link=Achievements
    |cate=Achievement-related elements
    }}
    <!-- fr version -->
    {{l10n/register|achievement|fr
    |link=Succès
    |cate=Éléments relatifs aux succès
    }}
    <!-- zh version -->
    {{l10n/register|achievement|zh
    |link=成就
    |cate=成就相关元素
    }}

    Please keep to the alphabetical order of the language codes, with English always at the very beginning.

    Saving the changes now finalizes the Chinese localization of {{achievement}}. While for a language like Chinese, which has a separate wiki, a copy-paste to that language wiki is still required (see the result on the zh wiki), languages without a separate wiki are already done by now.

    Lua-based templates

    For Lua-based templates, such as {{item}} or {{eicons}}, the l10n work might need to be done within the Lua module. However, the process is largely the same – translate the existing English messages and add them to the l10n section of the modules. In modules, the l10n section usually consists of a text table and might also contain certain l10n-related functions or settings. See Module:Item and Module:Exclusive for examples.

    Localization subtemplates and submodules

  • Footnotes