Changes between Version 8 and Version 9 of Internationalization
- Timestamp:
- Apr 13, 2014, 2:35:36 PM (10 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Internationalization
v8 v9 106 106 Plural functions require that you pass them two versions of the same message: a message in singular form (`number = 1`) and a message in plural form (`number != 1`). This is because those are the English plural forms. However, other languages may have more plural forms or no plural forms at all. That is why you must specify an integer, `number`, that is the number of items represented in your message. 107 107 108 TODO: s everal plurals in one sentence (use string formatting)108 TODO: sprintf for sentences with more than one item that can be in singular form or plural form. 109 109 110 110 === Using Context Functions === … … 124 124 * '''Unclear verb tenses or nouns'''. More often than not, the same English word may represent two or more different tenses of a verb, and also work as a noun or other type of word. If the message string is not clear enough as to which of those tenses is being used or whether the word is working as a verb or as a different type of word, you need a context. 125 125 126 === Using Format StringsInstead of Concatenating Strings in !JavaScript ===126 === Using String Formatting Instead of Concatenating Strings in !JavaScript === 127 127 128 128 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: … … 141 141 progressCaption = sprintf(translate("Uploading… (%f%%)"), Math.floor(100*done)); 142 142 }}} 143 144 == Formatting Dates in JavaScript == 145 146 Given a date in [http://en.wikipedia.org/wiki/Unix_time UNIX time], you can format the date using the following engine function: 147 148 {{{ 149 dateString = Engine.formatMillisecondsIntoDateString(unixTime*1000, translate("yyyy-MM-dd HH:mm:ss")); 150 }}} 151 152 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]. 143 153 144 154 = Internationalizing Data Files = … … 162 172 Once the message extraction system is properly configured to extract the translatable strings from a data file, translators will be able to translate those strings. But for those translations to be actually used, you must internationalize the !JavaScript that loads or uses the data to translate the loaded data at run time. 163 173 164 If the !JavaScript file obtains the data as a string, you can simply pass a variable that contains the translatable string to a global internationalization function such as `translate()` or `translateWithContext()`. 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: 174 If the !JavaScript file obtains the data as string that contains the complete message to translate, you can simply pass a variable that contains the translatable string to a global internationalization function such as `translate()` or `translateWithContext()`. 175 176 If the !JavaScript file reads the data from a plain text file, you can use the engine function `translateLines` to translate the file right after you read it: 177 178 {{{ 179 fileContent = Engine.translateLines(Engine.ReadFile(pathToFile)); 180 }}} 181 182 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: 165 183 166 184 {{{