GPT-ARB-Translator is a Python script that uses OpenAI GPT-3.5-turbo to translate your arb files. The script is ideal for developers working with Flutter and looking to localize their applications.
- Clone this repository:
git clone https://github.com/dextersjab/gpt-arb-translator.git
- Navigate to the cloned directory and install the required Python packages:
cd gpt-arb-translator
pip install -r requirements.txt
- Set your OpenAI API key as an environment variable:
export OPENAI_API_KEY='your-key-here'
Now you can run the script on the command line. The command-line arguments are:
indir
: The directory containing your input .arb files.outdir
(optional): The directory where the translated .arb files will be output. Defaults to the input directory if not specified.lang
(optional): The base language in which the key-value pairs are provided, specified as a 2-letter ISO 639-1 code. Defaults to 'en' if not specified.out_langs
(optional): Languages to translate into. Defaults to all languages found in the arb files inindir
.
- Run the script:
python translate_arbs.py --indir 'your/input/directory' --outdir 'your/output/directory' --entries key1='value1' key2='value2' --lang en
Let's say you have a base .arb file (app_en.arb) with the following content in English:
{
"hdtQuote": "The language of friendship is not words but meanings.",
"noMoat": "We have no moat."
}
Here's how you might use the script to translate this .arb file into all other languages in your output directory:
python translate_arbs.py --indir 'your/input/directory' --outdir 'your/output/directory' --lang 'en'
Alternatively, you could specify the output languages using --out_langs
.
Here's how you might use the script to translate this .arb file into French and Spanish:
python translate_arbs.py --indir 'your/input/directory' --outdir 'your/output/directory' --lang 'en' --out_langs fr es
- The translated .arb files will retain the structure of the original files, with the translated text inserted in place of the original text.
- Make sure to provide valid .arb files in the input directory.
- The script reads the 2-letter language codes from the .arb filenames in the input directory. It expects filenames in the format app_.arb.
- The script uses the OpenAI GPT-3.5-turbo model for translation.
- If the script encounters an error during translation, it will retry the request up to 3 times with an exponential backoff.
- The OpenAI API key is required to use the OpenAI GPT-3.5-turbo model. Keep in mind that usage of the OpenAI API may incur costs according to OpenAI's pricing.