53 | | == Internationalizing Content that !JavaScript Files Load from Regular XML Files == |
54 | | TODO: translateObjectKeys |
| 53 | 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#MessageExtractionSystem message extraction system documentation.] |
| 54 | |
| 55 | == Internationalizing Content that !JavaScript Files Load from Data Files == |
| 56 | 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. |
| 57 | |
| 58 | 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: |
| 59 | |
| 60 | {{{ |
| 61 | translateObjectKeys(settings.ais, ["name", "description"]); |
| 62 | }}} |