Changes between Version 15 and Version 16 of Internationalization


Ignore:
Timestamp:
Apr 19, 2014, 1:01:42 PM (10 years ago)
Author:
sanderd17
Comment:

Simulation translation

Legend:

Unmodified
Added
Removed
Modified
  • Internationalization

    v15 v16  
    4545</object>
    4646}}}
    47 == Internationalizing !JavaScript Code Within GUI Files ==
     47== Internationalizing !JavaScript Code Within GUI XML Files ==
    4848Simply put: '''you cannot'''.
    4949
     
    8787}
    8888}}}
    89 = Internationalizing !JavaScript Files =
     89= Internationalizing !JavaScript GUI Files =
    9090== Internationalizing Strings in !JavaScript ==
    9191To internationalize a string in a 0 A.D. !JavaScript file, simply use the following global functions:
     
    9999These functions return the specified message translated into the current language. If that language is the source language or if there is no translation for the specified message, these functions return the specified message.
    100100
     101
    101102=== Using Plural Functions ===
    102103Plural 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.
     
    147148
    148149You 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].
     150
     151= Internationalizing !Javascript Simulation Files =
     152
     153Internationalizing js simulation files isn't easy, as the simulation is supposed to be deterministic, and completely equal between different players in a game (which may use different locales). That's why the simulation may only mark strings for translation (those strings will can found by the message extracting tool), and the actual translation has to happen in the unsynced GUI files.
     154
     155Marking a string for translation is done with the {{{markForTranslation(message)}}} and {{{markForTranslationWithContext(context, message)}}} functions.
     156
     157When you mark strings for translation, they're not translated yet. The string you pass still has to be translated in the GUI, but at least the GUI doesn't have to care for the actual text in the string, it just has to know the string is translatable.
     158
     159For this purpose, the notifications methods in the GUI accept extended objects in the form of
     160{{{
     161{
     162  message: "%(person) string in printf style",
     163  parameters: {person: "me"},
     164  translateMessage: true,
     165  translateParameters: ["person"],
     166}
     167}}}
     168
     169The {{{parameters}}} object gets translated with the keys in the {{{translateParameters}}} list thanks to the {{{translateObjectKeys}}} method described at the end of the page. This gives you some ways to translate only certain parameters. Note that the translatable parameters have to be marked for translation in some way, else they won't arrive in the .pot file, and never get translated. Then the message is translated if wanted, and is passed through printf with the translated parameters. This should result in a nicely translated message, without problems for synchronising the GUI.
    149170
    150171= Internationalizing Data Files =