gpt-i18n-translator is a Node.js script that compares two language files and adds missing translations. It uses the OpenAI API to generate the missing translations.
To install the script globally, use the following command:
npm install -g gpt-i18n-translator
-
Create the
.env
File:Create a
.env
file in the current directory by copying the provided.env.example
file:cp $(npm root -g)/gpt-i18n-translator/.env.example .env
-
Edit the
.env
File:Open the
.env
file in a text editor and add your OpenAI API key and model information:OPENAI_API_KEY=your_actual_openai_api_key OPENAI_MODEL=your_actual_openai_model (e.g. gpt-4o)
Run the script with the following parameters: target language, path to the original language file, and path to the foreign language file to be updated.
gpt-i18n-translator <target_language> <original_file_path> <foreign_file_path>
Suppose you want to add missing translations from German to English:
gpt-i18n-translator en ./path/to/de/translation.json ./path/to/en/translation.json
<target_language>
: The target language for translation (e.g.,en
for English).<original_file_path>
: Path to the original language file (e.g.,./path/to/de/translation.json
).<foreign_file_path>
: Path to the foreign language file to be updated (e.g.,./path/to/en/translation.json
).
If you want to develop or customize the script locally, you can install it in your project directory:
yarn install
Use
yarn dev
To test local installation.
This project is licensed under the MIT License.
- Bernard Teske www.bernardteske.de