GithubHelp home page GithubHelp logo

mohi / json-deepl-translate Goto Github PK

View Code? Open in Web Editor NEW

This project forked from saigesp/json-translate

0.0 0.0 0.0 51 KB

Translate json files with deepl API

License: GNU Lesser General Public License v2.1

Python 100.00%

json-deepl-translate's Introduction

json-deepl-translate

CLI tool to translate json files automatically using Deepl API

Open issues Open PRs License Release Contributors Commits

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.

The supported languages are the same as DeepL.

Requires Python3

python json_translate /path/to/file/en_US.json --locale FR

Install

  1. Clone this repository.
  2. Create a virtual environment.
  3. Install dependencies:
pip install -r requirements.txt
  1. 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)

If you wish to upgrade to a paid account, you will need to add the paid api endpoint in the .env file:

DEEPL_API_ENDPOINT=https://api.deepl.com/v2/translate

Other parameters can also be overwritten:

SLEEP_BETWEEN_API_CALLS=0.01
INDENTATION_DEFAULT=2
ENCODING=utf-8

Usage

  1. Execute the command with the file path and the language you want to generate
python json_translate /home/user/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.

Optional parameters

-l, --locale          Target language to translate the file. Defaults to "en" (English)
-sl, --source-locale  Source language translating from (Optional, required for glossaries)
-g, --glossary        Glossary ID to use when translating (Optional)
-o, --output          Output file name. Defaults to "<target locale>.json" (ex: en.json)
-s, --sleep           Sleep time between API calls. Defaults to 0.01 (seconds)
-i, --indent          Output file indentation spaces. Defaults to 2
--encoding            Input & output file encoding. Defaults to UTF-8
--skip                Keys to skip in the json file (they won't be translated)
--log                 Display translations as they are being translated

Note that sleep, indentation and encoding can also be defined with variables in the .env file but they are overwritten with the values of the command.

Example file

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 --log

API usage

You can check your API usage with

curl -H "Authorization: DeepL-Auth-Key YOUR-API-KEY-HERE" https://api-free.deepl.com/v2/usage

Contributing

See the contributing guide for detailed instructions on how to get started.

License

This repository is available under GNU LESSER GENERAL PUBLIC LICENSE v2.1 (LGPL).

json-deepl-translate's People

Contributors

saigesp avatar iparr avatar madeinshinea avatar mohi avatar dotfortun3-code avatar juliusjacobitz avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.