Help:模板的国际化与本地化

来自Terraria Wiki
IsConeNotConical讨论 | 贡献2020年8月9日 (日) 01:26的版本 (创建页面,内容为“{{Translation|needed}} {{see also|Terraria Wiki:Projects#Language projects{{!}}Language projects}} On the Terraria Wikis, a template is '''{{wikipedia|i18n}}-ready'…”)
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)
跳转至: 导航搜索
此页面的(部分)内容需要被翻译。
你可以帮助我们来翻译此页面

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[编辑源代码]

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,[1] 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[编辑源代码]

If the target language does not have its own wiki subdomain and instead exists within the English wiki on language subpages,[2] 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 cs 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[编辑源代码]

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.

Footnotes[编辑源代码]