| 150 | |
| 151 | = Internationalizing !Javascript Simulation Files = |
| 152 | |
| 153 | Internationalizing 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 | |
| 155 | Marking a string for translation is done with the {{{markForTranslation(message)}}} and {{{markForTranslationWithContext(context, message)}}} functions. |
| 156 | |
| 157 | When 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 | |
| 159 | For 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 | |
| 169 | The {{{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. |