General Translation  

Deploying to Production

How to deploy your project to production with General Translation

Overview

This is a guide on how to use the General Translation CLI tool to deploy your site to production. This CLI tool scans through your project and looks for content to translate. It handles both the dictionary and the <T> component formats.

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:

GT_API_KEY=YOUR_API_KEY
GT_PROJECT_ID=YOUR_PROJECT_ID

Install the CLI tool:

npm i gt-react-cli

Next, run the following command:

shell
npx gt-cli translate

By default, running the command above will enable on-demand translation for all supported locales.

Translations are usually ready within a minute, but could take up to five minutes in periods of high demand. When translations are ready you should be able to access them via the cache in both your local and production projects.

Pre-Translation

By default, your project will be translated on-demand depending on the locales of the users who visit your site. Since these on-demand translations may take a few seconds to complete, you can pre-translate your project to serve cached translations to your users.

You can select which locales you want to pre-translate by specifying them in the command.

npx gt-cli translate --locales fr es ja

For more information on specifying locales, read our article about locale strings here.

If the script is successful, you should see a similar message to the following:

 Success! {number} tokens received and ready for translation at runtime.
To translate your app in advance, rerun with the --locales flag. For example: `npx gt-cli translate --locales fr`

Dry run

To test a dry run of the CLI tool, you can use the --dry-run flag. Running the CLI tool with this flag allows you to validate proper usage of the <T> components or dictionary formats in your codebase, without actually sending data to our servers.

npx gt-cli translate --dry-run

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

On this page