General Translation  
Next.js

The CLI Tool

The General Translations CLI tool

Overview

This is a reference doc on the General Translation CLI tool. Read more about gt-next-cli here.

For a step by step guide, check out the Deploying to Production guide.

Installation

npm i gt-next-cli --save-dev

What does the CLI tool do?

The CLI tool is used for managing your project and your translations. There are a two main commands you should be aware of: translate and setup.

  • The translate command is meant to be added to the CD pipeline. It is used to scan your project for content to be translated. The content is then uploaded to a CDN or added to your app bundle to be used at runtime.
  • The setup command is used to automatically integrate the General Translation library into your project. It will scan through your project and wrap any JSX content with a <T> component.

Translating

To use the CLI tool, run the following command from the root of your project:

shell
npx gt-next-cli translate

For Production Use 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 specify your production API key and Project ID in your environment variables.

Flags

PropTypeDefault
--api-key
string
-
--project-id
string
-
--options
string
gt.config.json
--new
string
-
--dictionary
string
-
--dry-run
boolean
false
--ignore-errors
boolean
false
--inline
boolean
true
--src
string
-

When running the CLI tool for the first time, it will attempt to create a gt.config.json file in the root of your project. This file contains metadata about your project that is used to translate your content.


Setup

Additionally, the CLI tool can automatically scan and setup your project for translation. If you are using General Translation for the first time, we recommend running the setup to get started.

shell
npx gt-next-cli setup

Stash your changes!

This will modify your codebase, so make sure to either stash or commit your changes first.

Running this command will wrap <T> components around the top level of JSX elements which contain translatable content.

It will also wrap any non-static content with <Var> components.

Here are some examples of what the scan will convert:

<div>Hello, World!</div>

Will be converted to:

<T id="">Hello, World!</T>

The CLI will only wrap direct children inside JSX elements. It will wrap other JSX elements separately with their own <T> components.

Experimental

This feature is currently experimental and may not work perfectly. Please report any issues you run into here.

The CLI tool will also optionally wrap <GTProvider> components at the top level layout.tsx of your app, as well as modify the lang attribute in the <html> tag to dynamically set the language of your app.

Lastly, it will optionally add the withGTConfig plugin to your next.config.js file.

Flags

PropTypeDefault
--src
string
-

On this page