Translate JSON language files / i18n locales on the spot!
go-json-translate is a tool designed to easily translate JSON translation files. It's particularly useful for projects with large language files that need quick and efficient translation.
- Translate any standard JSON file using DeepL's free API
- Support for JSON files containing strings, numbers, and booleans
- Handles nested JSON files without limits
- Local database for translation caching to improve speed and reduce API calls
- Preserves variables in translated text (e.g.,
hello, {name}
->bonjour, {name}
) - Supports various enclosure tags:
{}
,#{}
,[]
English (Source):
{
"account": {
"breadcrumb": "Your Account",
"nav": {
"overview": "Overview",
"orders": "Orders",
"messages": "Messages ({num_new_messages})"
}
}
}
French (Translated):
{
"account": {
"breadcrumb": "Votre compte",
"nav": {
"overview": "Vue d'ensemble",
"orders": "Commandes",
"messages": "Messages ({num_new_messages})"
}
}
}
- Go 1.17 or higher
- DeepL API key
git clone https://github.com/gmonarque/go-json-translate
cd go-json-translate/src
go mod download
go build
Before using go-json-translate, configure the config.ini
file:
DEEPL_API_ENDPOINT = https://api-free.deepl.com/v2/translate
DEEPL_API_KEY = <your_api_key>
./go-json-translate -source_path=<path> -output_path=<path> -source_lang=<lang> -target_lang=<lang> [-ignored_fields=<fields>]
-source_path
: Path of the source JSON file(s), can be a folder or a single file-output_path
: Path for the output file(s). The output JSON files will have the same name as the source files, but with the appendix_translated
added. This is optionnal.-source_lang
: Current language of the file (use "autodetect" to let DeepL guess)-target_lang
: Language to translate the file into-ignored_fields
: (Optional) Fields to ignore, separated by semicolons-populate_db
: (Optional) Path to existing translation file to populate the database
# Translate files
./go-json-translate -source_path=folder/*.json -output_path=output/*.json -source_lang=fr -target_lang=en
# Populate database with existing translations
./go-json-translate -populate_db=existing_translations.json -source_lang=en -target_lang=cs
To use existing translations and only translate new strings, you can populate the database with your current translations:
- Run the tool with the
-populate_db
flag, specifying the path to your existing translation file:
./go-json-translate -populate_db=path/to/existing/cs.json -source_lang=en -target_lang=cs
-
Repeat this process for each language you have existing translations for.
-
After populating the database, run the translation process as usual. The tool will use the existing translations from the database and only translate new strings using the DeepL API.
BG, CS, DA, DE, EL, EN, ES, ET, FI, FR, HU, ID, IT, JA, KO, LT, LV, NB, NL, PL, PT, RO, RU, SK, SL, SV, TR, UK, ZH
AR, BG, CS, DA, DE, EL, EN-GB, EN-US, ES, ET, FI, FR, HU, ID, IT, JA, KO, LT, LV, NB, NL, PL, PT-BR, PT-PT, RO, RU, SK, SL, SV, TR, UK, ZH, ZH-HANS, ZH-HANT
Note: Not all source languages can be used as target languages. For the most up-to-date list, refer to DeepL's API documentation.
- Depends on DeepL's free tier API usage limits
- No support for JSON arrays
- Large files may cause instability depending on hardware
- Output JSON order may differ from the source file
Contributions are welcome! Please feel free to submit a Pull Request.
If you've translated something that could be useful to others, please submit a merge request with your translated file in the community-translated-files
folder.
This project is licensed under the MIT License.
For any questions or issues, please open an issue on GitHub.