Search code examples
localizationinternationalizationformatjs

Adding new translations


I'm using FormatJS to localize my app. There's a handy CLI to extract all the translations from the code base. I can generate the en.json file, and send it to the translator. When I get the translation back I can save this as fr.json. So far so good. What I don't understand is what to do when I'm adding new translations in my app. When I run formatjs extract again, I get a new en.js file, with all the keys. Obviously I don't want to send the whole thing again to the translator. I could diff the new en.json against the previous version but it's such a basic step that I feel like I must be missing something? I didn't find anything about this in the docs. How is this part of the workflow handled with FormatJS?


Solution

  • It seems like translation services typically take care of diffing the data. You send them the whole template file and they send back translation files will all the translated strings (new ones + ones that have already been translated). At least that's how it works with the provider my company uses. My workflow is as follow:

    • add new translations in the source code with intl.formatMessage()
    • formatjs extract to create the new en.json file (template file)
    • replace the translation files (e.g. es.json, fr.json etc.) with the new ones from the provider
    • formatjs compile to generate the machine files

    I also created a test to ensure that each key in en.json has a corresponding key in each translation file.