CLI Tool
How to pre-load translations with the GT CLI tool
Overview
This is a guide on how to use the General Translation CLI tool to pre-translate for your site. This CLI tool scans through your project and looks for content to translate. It then sends this content to the General Translation API to be translated which gets distributed to the CDN once translation has been completed. Read more about the CLI tool here.
This guide assumes that you have already integrated gt-next
or gt-react
into your project.
If you haven't, please follow the NextJS Quick Start Guide or the React Quick Start Guide before proceeding.
For production only!
Because this CLI tool publishes translated content to the CDN, it is meant to only be used for production builds, and should not be used in development. Before running this command, please make sure you are on the branch that will be used for production. Remember to also use your production API key and Project ID.
Usage
Basic usage
Add your API key and Project ID to your environment variables.
You can do this by adding the following to your .env
file or directly to your environment:
To pre-translate your content, you can run the following command:
Translations are usually ready within a minute, but could take up to five minutes in periods of high demand. When translations are ready should be able to access them via the cache in both your local and production projects.
Specifying locales
You can select which locales you want to pre-translate by specifying them in the command.
For more information specifying locales, read our article about locale strings here.
Specifying credentials
You can also specify your credentials directly in the command. Typically, this can be read directly from your environment.
If the script is successful, you should see the following message in the console:
Notes
- The CLI tool allows you to pre-translate content.
- This is meant to be used for production builds only.
- You can specify which locales you want to pre-translate.
Next steps
- Learn more about the CLI tool and pre-translation.
- Learn more about locale strings.