The following libraries are used in the translation process:
A script runs and watches for changes in the yarn start
/ gatsby develop
command which automatically dumps any strings it picks up into extractedTranslations/en/common.json, it won't however pick up strings that are not passed into translation components. When you notice common.json
has changed, that's a good indicator to run through the translation process.
The helper script for updating translation files can be ran using yarn extract
, which runs import-i18n.js
This script does a few essential tasks
- Deletes the current common.json file to remove old strings no longer present on the site.
- These are backed up in crowdin if needed later
- Runs the string extraction process to extract all new strings on the site into extractedTranslations/en/common.json
- Imports new and existing translated strings from
translationImport/common_{locale}.json
- Checks all strings, identifies if any are missing for each locale
- Does a "close enough match" for translations that are approximately "70%" similar or so in case a minor change was made on the English site since the last translation
- Dumps all completed strings into their appropriate
src/locales/...
folder - Dumps missing and "close enough" strings into
pendingTranslations/{locale}/needsupdate.json
- These strings will need to be handed to the translation team, sending them the updated
extractedTranslations/en/common.json
will suffice.
- These strings will need to be handed to the translation team, sending them the updated
There are two components you can use to translate strings, the t()
function, and the <Trans>
component.
Any strings you pass to these will be collected by the import script during the extraction/development process, and when deploying the site will be translated if a matching translation is found.