Hello there! We are conducting a survey to better understand the user experience in making a first edit. If you have ever made an edit on Gamepedia, please fill out the survey. Thank you!

Help:I18n & l10n for Templates

From Terraria Wiki
Jump to: navigation, 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.

Preparation[edit source]

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[edit source]

If the target language has its own wiki subdomain, e.g. German (de) or Chinese (zh), the following steps are to be taken:

  • Port {{lang}} to the target language's wiki. Refer to the de and zh versions for examples.
  • Port {{l10n}} and {{l10n/register}} to the target language's wiki. This is as simple as copying the code of the English version.
  • 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.

For languages without a separate wiki[edit source]

If the target language does not have its own wiki subdomain and instead exists within the English wiki on language subpages, e.g. Italian (it) or Spanish (es), the following step is to be taken:

  • Initialize the translation database of the target language: Create and/or fill Template:Tr/db-[langcode], (e.g. Template:Tr/db-es for Spanish). Refer to the es, it, and cz versions for examples. If you still don't know how to set it up, simply put {{#dplvar:set|_tr-[langcode]:__OK__|ok}} (e.g. {{#dplvar:set|_tr-es:__OK__|ok}} for Spanish) as the content of the template.

Localization[edit source]

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 {{hint}} 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 {{hint}}, we can see the en and it l10n information:

<!-- 
//register localization info:
-->{{l10n/register|hint|en<!--
	-->|hint=Hint:<!-- 
	-->|default=No hint provided.<!-- 
-->}}<!-- 
//it version
-->{{l10n/register|hint|it<!-- 
	-->|hint=Suggerimento:<!-- 
	-->|default=Nessun suggerimento fornito.<!-- 
-->}}<!-- 

-->

Now, add the translated Chinese messages:

<!-- 
//register localization info:
-->{{l10n/register|hint|en<!--
	-->|hint=Hint:<!-- 
	-->|default=No hint provided.<!-- 
-->}}<!-- 
//it version
-->{{l10n/register|hint|it<!-- 
	-->|hint=Suggerimento:<!-- 
	-->|default=Nessun suggerimento fornito.<!-- 
-->}}<!-- 
//zh version
-->{{l10n/register|hint|zh<!-- 
	-->|hint=提示:<!-- 
	-->|default=未提供提示。<!-- 
-->}}<!-- 

-->

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 {{hint}}. 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[edit source]

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.