Introducing i18n-cli
i18n-cli is an innovative command-line interface tool designed to simplify the translation process of locale files using the cutting-edge OpenAI API. This tool is particularly beneficial for developers and global teams looking to translate JSON-based locale files efficiently and with quality assurance.
Installation
Getting started with i18n-cli is straightforward. It requires installation via Go, which can be done using the following command:
go install github.com/pandodao/i18n-cli@latest
This command installs the latest version of i18n-cli, ensuring that users benefit from the most up-to-date features and fixes.
How to Use i18n-cli
Using i18n-cli involves a few simple steps that make translation seamless and automated. Before running the tool, make sure you have set the OpenAI API key in your environment:
export OPENAI_API_KEY=YOUR_API_KEY
Once your API key is set, you can use i18n-cli to translate your locale files with this basic command setup:
i18n-cli translate \
--dir ./locales \
--source ./locales/en-US.json \
--independent ./independent.json
Let’s break down the components of this command:
-
--dir
: This option specifies the directory where your locale files are stored. In the example,./locales
indicates that the directory is in the current working directory. -
--source
: This refers to the source locale file, which acts as a reference for the tool to understand what needs translating. In this case, the source file isen-US.json
. -
--independent
: This option lists a file that includes text not directly aligned to a specific source file, providing an additional resource for reference during translation.
i18n-cli orchestrates the entire translation workflow by scanning the specified directory for locale files, querying translations via the OpenAI API, and then writing the resulting translated text back into these files. This process allows for a streamlined translation cycle, significantly reducing the manual workload for developers.
Special Features
i18n-cli provides flexibility regarding which content to translate:
- It ignores existing values in locale files, concentrating on generating new translations.
- If there is a need to translate a specific string, including an exclamation mark "!" at the beginning of the string signals the tool to translate it.
- To update or regenerate translations entirely for specific phrases, users can remove the desired key/value pairs from the JSON file so that i18n-cli generates fresh translations.
Conclusion
i18n-cli effectively bridges the gap between automated translation and developer needs in a multi-lingual project setup. By seamlessly integrating with the OpenAI API and offering powerful options for managing locale files, it stands out as an essential tool for developers aiming to internationalize their software products efficiently.