Changes between Version 8 and Version 9 of Internationalization


Ignore:
Timestamp:
Apr 13, 2014, 2:35:36 PM (10 years ago)
Author:
Adrián Chaves
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Internationalization

    v8 v9  
    106106Plural 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.
    107107
    108 TODO: several plurals in one sentence (use string formatting)
     108TODO: sprintf for sentences with more than one item that can be in singular form or plural form.
    109109
    110110=== Using Context Functions ===
     
    124124 * '''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.
    125125
    126 === Using Format Strings Instead of Concatenating Strings in !JavaScript ===
     126=== Using String Formatting Instead of Concatenating Strings in !JavaScript ===
    127127
    128128You 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:
     
    141141progressCaption = sprintf(translate("Uploading… (%f%%)"), Math.floor(100*done));
    142142}}}
     143
     144== Formatting Dates in JavaScript ==
     145
     146Given a date in [http://en.wikipedia.org/wiki/Unix_time UNIX time], you can format the date using the following engine function:
     147
     148{{{
     149dateString = Engine.formatMillisecondsIntoDateString(unixTime*1000, translate("yyyy-MM-dd HH:mm:ss"));
     150}}}
     151
     152You 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].
    143153
    144154= Internationalizing Data Files =
     
    162172Once 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.
    163173
    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:
     174If 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
     176If 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{{{
     179fileContent = Engine.translateLines(Engine.ReadFile(pathToFile));
     180}}}
     181
     182If 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:
    165183
    166184{{{