Translate json files with deepl API
Usually multi-language projects developed with a javascript framework (Angular, Vue...) base their translations on json files with different nesting levels. This small project allows you to generate new files for other languages while keeping the same structure.
- Works with Python3
python json_translate /path/to/file/en_US.json --locale es --output es_ES.json --indent 4 --sleep 0.5
See more options with
python json_translate --help
You can check the supported languages at this link: DeepL Translate Text Request Parameters (parameters source_lang
and target_lang
)
-
Create virtual environment
-
Install dependencies:
pip install -r requirements.txt
- Create an
.env
file with:
DEEPL_AUTH_KEY=your-key-here
You can get a free deepl developer account in https://www.deepl.com/pro-checkout/account (Credit card needed)
- Execute the command with the file path and the language you want to generate
python json_translate /home/user/my_project/locales/en_US.json --locale ES --output es_ES.json
The script will create an
es_ES.json
file in the same folder as the source file.
-l, --locale Language target to translate. Defaults to "en"
-o, --output Output file name. Defaults to "en.json
-s, --sleep Sleep time between API calls. Defaults to 0.01s
-i, --indent Output file indentation spaces. Defaults to 2
--skip Keys to skip (they won't be translated)
Translate the example file /tests/data/en_US.json
to spanish:
python json_translate tests/data/en_US.json --locale ES --output es_ES.json --skip lorem ipsum
You can check your API usage with
curl -H "Authorization: DeepL-Auth-Key YOUR-API-KEY-HERE" https://api-free.deepl.com/v2/usage
See the contributing guide for detailed instructions on how to get started.
Run tests with:
python -m unittest discover
This repository is available under GNU LESSER GENERAL PUBLIC LICENSE v2.1 (LGPL). See details.