next-intl
Automatically translate your next-intl project in under 5 minutes
Overview
This tutorial shows you how to manage your project’s translation files automatically if you’re using next-intl.
We’ll follow these four 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 can get these from the General Translation dashboard.
GT_API_KEY=<your-api-key>
GT_PROJECT_ID=<your-project-id>Step 2: Install gtx-cli
Install the gtx-cli tool in your project.
npm i gtx-cliyarn add --dev gtx-clibun add --dev gtx-clipnpm add --save-dev gtx-cliStep 3: Create a gt.config.json file
Create a gt.config.json file in the root of your project.
{
"defaultLocale": "en",
"locales": ["zh", "es", "ja"],
"files": {
"json": {
"include": ["i18n/[locale]/*.json"]
},
},
}Feel free to customise the gt.config.json file to suit your needs. See the configuration docs for more information.
Update the json file format so that the include path matches your project structure.
Translations will preserve the original string syntax.
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.
{
"scripts": {
"translate": "npx gtx-cli translate",
"build": "npm run translate && <your build command>"
}
}This will generate translations for all 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! Your project will now automatically update all your translation JSON files whenever your project changes.
Notes
- You can automatically add translations to your project with the
gtx-cli translatecommand. - If you want to commit your translation files, you can instead run the
gtx-cli translatecommand before committing. - To configure the output path for your translations, see the configuration docs.
Next steps
- See the usage guide for the CLI tool.
How is this guide?