Changes between Version 4 and Version 5 of Internationalization


Ignore:
Timestamp:
Apr 13, 2014, 1:27:00 PM (10 years ago)
Author:
Adrián Chaves
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Internationalization

    v4 v5  
     1[[TOC]]
     2
    13= Internationalizing GUI Files =
    2 TODO
     4== Internationalizing Captions and Tooltips ==
     5To internationalize a caption or tooltip (or any other XML attribute) of a GUI XML `object` element, remove the attribute from the `object` element that contains it, and add a new `translatableAttribute` element within the `object` element that used to contain the old attribute, with the name of the old attribute as the value of the `id` attribute of this new element, and the value of the old attribute as the content of this new element.
     6
     7  ''' Note:'''  Use "caption" as id of translatableAttribute to translate the caption of an object element.
     8
     9|| '''Original''' || `<object type="button" tooltip="Adjust game settings.">Options</object>` ||
     10|| '''Internationalized''' || `<object type="button">    <translatableAttribute id="caption">Options</translatableAttribute>    <translatableAttribute id="tooltip">Adjust game settings.</translatableAttribute></object>` ||
     11
     12== Internationalizing Captions By Parts ==
     13You might need to internationalize only parts of a caption. This is the case when, for translators’ sake, you want to mark each paragraph of a multiline caption for translation, or when you want to strip out formatting content (such as "[font]" tags) from the translatable content.
     14
     15The solution here is to use the `attribute` element in combination with `keep` and `translate` elements as follows:
     16
     17|| '''Original''' || `<object type="text">This is a paragraph.This is another paragraph.</object>` ||
     18|| '''Internationalized''' || `<object type="text">    <attribute id="caption">        <translate>This is a paragraph.</translate>        <keep>\n\n</keep>        <translate>This is another paragraph.</translate>    </attribute></object>` ||
     19
     20== Internationalizing !JavaScript Code Within GUI Files ==
     21Simply put: '''you cannot'''.
     22
     23You can call any of the global internationalization functions described below, however, strings passed to these functions are not parsed by the message extraction system, which means that translators won’t be able to actually translate the string.
     24
     25Move any !JavaScript code that requires internationalization of “hard-coded” strings into a function of a separate !JavaScript file. The message extraction system will successfully extract !JavaScript strings from !JavaScript files. You can then call that function from your GUI file. For example:
     26
     27|| '''Original''' || XML file:[[BR]]`<action on="Load">    this.caption = "Build:" + ``Engine.GetBuildTime();</action>` ||
     28|| '''Wrong''' || XML file:[[BR]]`<action on="Load">    this.caption = sprintf(translate("Build: %(buildTime)s"), { buildTime: Engine.GetBuildTime() });</action>` ||
     29|| '''Internationalized''' || XML file:[[BR]]`<action on="Load">    this.caption = getBuildTimeString()</action>`[[BR]][[BR]]!JavaScript file included by the GUI file:[[BR]]`function getBuildTimeString(){    return sprintf(translate("Build: %(buildTime)s"), { buildTime: Engine.!GetBuildTime() });}` ||
    330
    431= Internationalizing !JavaScript Files =
     
    3663TODO: sprintf.
    3764
    38 = Internationalizing Data Files (JSON, TXT, XML) =
     65= Internationalizing Data Files =
    3966Internationalizing strings from data files that are loaded by !JavaScript files is a two-step process. You must:
    4067