2 | | TODO |
| 4 | == Internationalizing Captions and Tooltips == |
| 5 | To 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 == |
| 13 | You 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 | |
| 15 | The 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 == |
| 21 | Simply put: '''you cannot'''. |
| 22 | |
| 23 | You 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 | |
| 25 | Move 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() });}` || |