JSON Files
How to use General Translation to set up automatic translation for your project's JSON files
Overview
gtx-cli
can be used to automatically translate your project's JSON files, regardless of what i18n library you are using.
Note:
We currently support custom string syntax and formatting for the following i18n libraries: next-intl
, i18next
, gt-next
, gt-react
.
If you are using a different i18n library, the translation results may not be accurate for strings with custom syntax and formatting (for example, ICU messages). Don't see your favorite library? Please let us know, and we will add it as soon as we can!
We will follow these 4 steps:
Tip:
Avoid the hassle of using translation files with the <T>
component.
Step 1: Add your environment variables
Add your production API key and project ID to your environment variables.
This is necessary to use the gtx-cli
tool.
You get these from the General Translation dashboard.
Step 2: Install gtx-cli
Install the gtx-cli
tool in your project.
Step 3: Initialize your project with the gtx-cli init
command
Run the gtx-cli init
command to configure your project.
Step 4: Add the gtx-cli translate
command to your build process
Add the gtx-cli translate
command to your build or CI process before the build command to automatically add translations to your project.
This will generate translations for all of your locales and save them to your project. If you want to commit these files to your repo, you can instead run this command before committing.
You're done! Now your project will automatically update all of your translation JSON files any time your project changes.
Notes
- You can automatically add translations to your project with the
gtx-cli translate
command. - If you want to commit your translation files, you should run the
gtx-cli translate
command before committing. - To configure the output path for your translations, see the configuration docs.
Next steps
- See the usage guide for the cli tool.
- If you want to see live translations in development (think hot reload), check out the
<T>
component.