Translate
How to translate your project
Usage
Note: This command requires a production API key! Get one on the platform.
Overview
The gt-react-cli translate
command translates your project. It traverses your project's file tree and translates any content wrapped in a <T>
component.
Additionally, it includes content from the dictionary file (if one is provided).
This command is the primary way of using the General Translation API and related services.
For Production Use Only!
This command is meant 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 (GT_API_KEY
) and Project ID (GT_PROJECT_ID
) in your environment variables.
Usage
There are three ways to use the translate
command. Methods 2 and 3 require a production API key:
The behavior of the command is controlled by the flags. See the Parameters section for more details.
Method 1: Validate your project's <T>
components and dictionary file.
This method is useful for validating your project's <T>
components and dictionary file.
This ensures that your project is correctly configured and that the translations will be valid and accurate.
Method 2: Translate your project and save the translations on the GT CDN.
This method allows you to translate your project using General Translation's services and automatically saves the translations on the GT CDN.
This is the recommended method for most projects.
Method 3: Translate your project and save the translations to your codebase.
This method allows you to translate your project and save the translations to your codebase.
gt-react
can then serve these local translations to your users, rather than using General Translation's public CDN.
This method is useful if you are using a custom CMS, or do not want to use the GT CDN.
Parameters
Parameter | Description | Type | Optional | Default |
---|---|---|---|---|
--api-key | Specify a production API key | string | true | |
--project-id | Specify the project ID | string | true | |
--version-id | Specify a version ID (by default, a hash of the content) | string | true | |
--config <path> | Specify a path to the GT config file | string | true | "gt.config.json" |
--tsconfig, --jsconfig <path> | Specify a path to the TS or JS config file | string | true | |
--src <paths> | Specify the source directory(s) to scan | [string] | true | ./src && ./app && ./pages && ./components |
--dictionary <path> | Specify a path to the dictionary file | string | true | |
--inline | Include inline <T> tags in addition to the dictionary | boolean | true | true |
--timeout | The timeout for the translation request in seconds | number | true | 600 |
--new, --locales <locales> | Locales to translate your project into | [string] | true | |
--default-locale <locale> | The source locale for the project | string | true | en |
--ignore-errors | Ignore errors and force translation for valid content | flag | true | false |
--dry-run | Dry run the command | flag | true | false |
--no-wait | Do not wait for the translations to complete before exiting | flag | true | false |
--no-publish | Do not publish the translations to the CDN | flag | true | false |
-t, --translations-dir <path> | The directory to save the translations to | string | true |
All of these parameters are optional and can be alternatively provided in the gt.config.json
file.
Do not add your API key to the gt.config.json
file!
You should set it as an environment variable instead. The CLI will automatically read GT_API_KEY
if it is set.
There are a few key parameters:
Parameter | Description |
---|---|
--dry-run | This flag will cause the CLI to parse and validate your project, but will not communicate with the GT API. This is useful for validating your codebase. |
--api-key | Unless you are using --dry-run , you must provide a production API key. |
--project-id | Similarly, unless you are using --dry-run , you must provide a project ID. |
-t, --translations-dir | The directory to save the translations to. You should provide this if you would like to use local translations, and want to save them to your codebase. |
--no-publish | Similarly, if you are using local translations, and do not want to make your translations publicly available on the GT CDN, you can use this flag. |
--new, --locales <locales> | Locales to translate your project into. These will be appended to the locales specified in your gt.config.json file. |
Configuration file
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.
Read more about the gt.config.json
file here.