@stratupai/translation-tool
v1.0.8
Published
Tool to create locale translation files with Google Cloud Translate
Downloads
16
Readme
@stratupai/translation-tool
A command-line tool for generating translation files for i18next using the Google Cloud Translate API (Language Detection Model v2).
Implement Internationalization with the help of i18next.
Getting Started
Before using this tool, ensure you have enabled the Google Cloud Translation API and obtained the necessary credentials. Please refer to the Google Cloud Translation API Documentation for detailed instructions.
Step 1: Enable Google Cloud Translation API
- Go to Google Cloud Console.
- Select your project.
- Navigate to APIs & Services > Cloud Translation API.
- Enable the API.
Step 2: Obtain Credentials
- Create the access credentials as described in the Google Workspace documentation.
- Rename the credentials file to
credentials.json
. - Place
credentials.json
in the root directory of your project.
For a detailed walkthrough, you can watch this video tutorial.
Step 3: Installation
Install the package via npm:
npm i @stratupai/translation-tool --save-dev
Step 4: Verify Installation
Type the following command in your terminal to check the default configuration:
translate
Usage
Default configuration:
{
"localesPath": "public/locales",
"credentialsPath": "credentials.json",
"sourceLanguage": "en",
"targetLanguages": [
"ar",
"fr",
"es",
"ja"
]
}
The translate
command-line tool offers various options and commands to facilitate translation tasks. Below are the available options and commands along with examples of how to use them:
Options
-l, --localesPath <path-to>
: Specifies the path for the locales directory. By default, it uses the path specified in the configuration file.-c, --credentialsPath <path>
: Specifies the path for the credentials file. By default, it uses the path specified in the configuration file.-s, --sourceLanguage <code>
: Specifies the source language code or source locale folder. By default, it uses the source language specified in the configuration file.-t, --targetLanguages <codes...>
: Specifies the target languages to translate into. Multiple target languages can be provided, separated by spaces. By default, it uses the target languages specified in the configuration file.
translate -l src/locales -s en -t fr es de
Commands
Add or Update Key
modify-key <namespace> <key> <value>
: Adds or updates a key-value pair in the specified namespace and translates it.
translate modify-key common "greeting" "Hello, world!"
Translate
run-translations [languages...]
: Translates modified keys(keys prefixed with ^ symbol) and updates all translation files for the specified languages. Languages are optional, if not provided it looks for all source files to translate.
translate run-translations
update-namespace <namespace>
: Updates the entire translation file for the specified namespace and adds caret (^) to all keys. Example:translate update-namespace common
Note - For namespace just give the file name (do not add .json extension)
update-locales
: Updates all source folder files and adds caret (^) to all untranslated keys. Example:translate update-locales
For more information on each command and option, use the --help
flag with the command. For example:
translate run-translations --help
Internationalization
For examples of using i18next with React and Next.js, refer to the following resources:
Contributing
Contributions are welcome! Please read the Contributing Guidelines for details on how to contribute to this project.
License
This project is licensed under the ISC License.