Changes between Version 11 and Version 12 of Internationalization
- Timestamp:
- Apr 13, 2014, 10:08:30 PM (10 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Internationalization
v11 v12 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 9 '''Original:''' … … 12 12 <object type="button" tooltip="Adjust game settings.">Options</object> 13 13 }}} 14 15 14 '''Internationalized:''' 16 15 … … 21 20 </object> 22 21 }}} 23 24 22 == Internationalizing Captions By Parts == 25 23 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. … … 36 34 </object> 37 35 }}} 38 39 36 '''Internationalized:''' 40 37 … … 48 45 </object> 49 46 }}} 50 51 47 == Internationalizing !JavaScript Code Within GUI Files == 52 48 Simply put: '''you cannot'''. … … 59 55 60 56 XML file: 57 61 58 {{{ 62 59 <action on="Load"> … … 64 61 </action> 65 62 }}} 66 67 63 '''Wrong:''' 68 64 69 65 XML file: 66 70 67 {{{ 71 68 <action on="Load"> … … 73 70 </action> 74 71 }}} 75 76 72 '''Internationalized:''' 77 73 78 74 XML file: 75 79 76 {{{ 80 77 <action on="Load"> … … 82 79 </action> 83 80 }}} 81 !JavaScript file included by the GUI file: 84 82 85 !JavaScript file included by the GUI file:86 83 {{{ 87 84 function getBuildTimeString() … … 90 87 } 91 88 }}} 92 93 89 = Internationalizing !JavaScript Files = 94 90 == Internationalizing Strings in !JavaScript == … … 123 119 124 120 === Using String Formatting Instead of Concatenating Strings in !JavaScript === 125 126 121 You should '''never''' concatenate translatable strings, as the position of each member of the concatenation may change in other languages. Instead, use the `sprintf` global function for string formatting: 127 122 … … 132 127 progressCaption = "Uploading… (" + Math.floor(100*done) + "%)"; 133 128 }}} 134 135 129 '''Internationalized:''' 136 130 … … 139 133 progressCaption = sprintf(translate("Uploading… (%f%%)"), Math.floor(100*done)); 140 134 }}} 141 142 135 == Formatting Dates in JavaScript == 143 144 136 Given a date in [http://en.wikipedia.org/wiki/Unix_time UNIX time], you can format the date using the following engine function: 145 137 … … 147 139 dateString = Engine.formatMillisecondsIntoDateString(unixTime*1000, translate("yyyy-MM-dd HH:mm:ss")); 148 140 }}} 149 150 141 You can modify the format string (second parameter) as you wish, using any [https://sites.google.com/site/icuprojectuserguide/formatparse/datetime?pli=1#TOC-Date-Field-Symbol-Table ICU date formatting symbols]. 151 142 … … 153 144 Internationalizing strings from data files that are loaded by !JavaScript files is a two-step process. You must: 154 145 155 1. Configure the [wiki:Implementation_of_Internationalization_and_Localization#MessageExtraction Systemmessage extraction system] to extract the translatable strings from the data file.146 1. Configure the [wiki:Implementation_of_Internationalization_and_Localization#MessageExtraction message extraction system] to extract the translatable strings from the data file. 156 147 1. Use an internationalization function on the !JavaScript side after you load the data file. 157 148 … … 165 156 * Strings from JSON data defined within an XML element. 166 157 167 To configure the message extraction system to extract strings from a new data file, you must edit the `l10n/messages.json` file of the mod folder. In the `messages.json` file of the main mod, `public`, you can find examples of all the supported types of data extraction. For more information, see the [wiki:Implementation_of_Internationalization_and_Localization#MessageExtraction Systemmessage extraction system documentation.]158 To configure the message extraction system to extract strings from a new data file, you must edit the `l10n/messages.json` file of the mod folder. In the `messages.json` file of the main mod, `public`, you can find examples of all the supported types of data extraction. For more information, see the [wiki:Implementation_of_Internationalization_and_Localization#MessageExtraction message extraction system documentation.] 168 159 169 160 == Internationalizing Content that !JavaScript Files Load from Data Files == … … 177 168 fileContent = Engine.translateLines(Engine.ReadFile(pathToFile)); 178 169 }}} 179 180 170 If the !JavaScript file obtains the data as an object, you can use the `translateObjectKeys()` global function instead, which expects the object with the data and an array with the names of the object properties that must be translated. For example, from the game code: 181 171