When creating files for the target languages, please consider the following recommendations:
The filename should include the language code, e.g. whatever.fr.json for French. (This allows doloc to automatically detect the language of the source and target files.)
Make sure to update the translation file paths and to replace $API_TOKEN with your API token or set a corresponding environment variable.
The API token can be found or created in your doloc account.
With this setup, you can run npm run update-i18n to extract (new) translations, automatically translate and compile them! 🎉
Running the script
This script should be run by the developer after adding or updating translations - and not on the CI/CD pipeline.
Using the naming from FormatJS, doloc behaves like a “local translation tool” and not like a “cloud based translation service”.
(This highlights doloc’s lightweight and easy to use nature, which is a key differentiator from other translation services. 😉)
Handling explicit IDs
In case you use explicit IDs (i.e. not auto generated by FormatJS), then you need to take extra care when updating existing texts.
For every changed text, you need to clear the translations for that key in the target file, so that they are translated again!
Your API tokens generally should not be shared publicly.
Having said that, if your repository is private, it is acceptable to store the API token in your repository.
The worst-case scenario is that others might use your quota, but never access or change any of your data.
Of course, you can always revoke the token and create a new one if needed.
Configuration
The default configurations of react-intl and doloc work well together and cover most use cases.
For more advanced configurations, you can check the options of FormatJS CLI.
doloc can be configured by passing options in the URL - see Options for general information and JSON for specific options.