Changes between Version 6 and Version 7 of Internationalization
- Timestamp:
- Apr 13, 2014, 1:43:33 PM (10 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Internationalization
v6 v7 5 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 6 7 ''' Note:'''Use "caption" as id of translatableAttribute to translate the caption of an object element.7 ''' Note:''' Use "caption" as id of translatableAttribute to translate the caption of an object element. 8 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>` || 9 '''Original:''' 10 11 {{{ 12 <object type="button" tooltip="Adjust game settings.">Options</object> 13 }}} 14 15 '''Internationalized:''' 16 17 {{{ 18 <object type="button"> 19 <translatableAttribute id="caption">Options</translatableAttribute> 20 <translatableAttribute id="tooltip">Adjust game settings.</translatableAttribute> 21 </object> 22 }}} 11 23 12 24 == Internationalizing Captions By Parts == … … 15 27 The solution here is to use the `attribute` element in combination with `keep` and `translate` elements as follows: 16 28 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>` || 29 '''Original:''' 30 31 {{{ 32 <object type="text"> 33 This is a paragraph. 34 35 This is another paragraph. 36 </object> 37 }}} 38 39 '''Internationalized:''' 40 41 {{{ 42 <object type="text"> 43 <attribute id="caption"> 44 <translate>This is a paragraph.</translate> 45 <keep>\n\n</keep> 46 <translate>This is another paragraph.</translate> 47 </attribute> 48 </object> 49 }}} 19 50 20 51 == Internationalizing !JavaScript Code Within GUI Files == … … 25 56 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 57 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() });}` || 58 '''Original:''' 59 60 XML file: 61 {{{ 62 <action on="Load"> 63 this.caption = "Build:" + ``Engine.GetBuildTime(); 64 </action> 65 }}} 66 67 '''Wrong:''' 68 69 XML file: 70 {{{ 71 <action on="Load"> 72 this.caption = sprintf(translate("Build: %(buildTime)s"), { buildTime: Engine.GetBuildTime() }); 73 </action> 74 }}} 75 76 '''Internationalized:''' 77 78 XML file: 79 {{{ 80 <action on="Load"> 81 this.caption = getBuildTimeString() 82 </action> 83 }}} 84 85 !JavaScript file included by the GUI file: 86 {{{ 87 function getBuildTimeString() 88 { 89 return sprintf(translate("Build: %(buildTime)s"), { buildTime: Engine.!GetBuildTime() }); 90 } 91 }}} 30 92 31 93 = Internationalizing !JavaScript Files =