The CLI Tool
The General Translations CLI tool
Overview
This is a reference doc on the General Translation CLI tool.
Read more about gt-react-cli
here.
For a step by step guide, check out the Deploying to Production guide.
Installation
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:
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
Prop | Type | Default |
---|---|---|
--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 |
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.
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:
Will be converted to:
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.
After running the scan, you should manually review the output and make sure it is correct.
In particular, note that any non-static JSX Expressions {...}
will be wrapped in <Var>
components.
You may need to manually review and edit these cases.
Please report any issues you run into here.
Flags
Prop | Type | Default |
---|---|---|
--src | string | - |