Automation CLI tool that, using the DeepL API, generates a JSON or a PO file from a given source file.
Project description
Polyglot - Automate translations with DeepL
Polyglot is a CLI tool that automates translation tasks and can be easily integrated into your python softwares. Using the DeepL API, Polyglot generates a translated file from a given source file.
Supported files
Polyglot is born to translate JSON and PO files, but now it supports other files. This is the complete list:
- json
- po and pot
- docx (Microsoft Word)
- pptx (Microsoft PowerPoint)
- html and htm
- raw text files like .txt or .dat
⚠️ If you want to translate PDFs, rember to enable the PDF translations from your DeepL API account.
Installation
Install Python if you haven't already done so, then use pip to install Polyglot.
pip install polyglot-translator
Then you can run Polyglot by running:
python -m polyglot
And that's all.
Soon the whole script will be packaged for other package managers like pacman, apt and brew.
Usage
There are four available commands: translate, set_license, print_usage_data and print_supported_languages.
Translate
"Translate" is the main feature of Polyglot. It reads the passed file and creates one or more new files with the translations. It creates a new file with the translations and doesn't edit the source file.
ℹ️ In the case of a PO and POT files, it returns both a PO and an MO file.
Command options
Option | Required | Description |
---|---|---|
-s, --source-file | yes | The file to be translated. |
--to, --target-lang | yes | the code of the language into which you want to translate the source file |
-d, --destination-dir | no | The directory where the output file will be located. Will be used the working directory if this option is invalid or not used. |
--from, --source-lang | no | Source file language code. Detected automatically by DeepL by default. Specifying it can increase performance and make translations more accurate. |
Basic usage
E.g.: we have a .json source in English and we want to translate it in Italian.
python -m polyglot translate -s en.json --to IT
Advanced usage
E.g.: we have a .po source in English and we want a .po file translated into Japanese with the corresponding .mo file in our home. We specify the source language to benefit DeepL.
python -m polyglot translate -s en.po --to JA -d $HOME --from EN-US
Set DeepL API key
DeepL provides you with a key that allows you to use its API. So, Polyglot requires this key to work and will ask you for it on your first use. You can use the following command to set or change the key manually.
python -m polyglot set-license
Print usage info
It returns DeepL usage info related to your API key, run with:
python -m polyglot info
Print supported languages
It returns the list of languages currently supported by DeepL, run with:
python -m polyglot languages
Dependencies
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for polyglot-translator-2.2.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | bc6da7de9918544ecdfd4af83ad7bdba9bf4a7b38c0922045022bf3f5fa40ad8 |
|
MD5 | de9e450d898ba776ba3c1bddb7d05fd0 |
|
BLAKE2b-256 | 1eb6a903391389320934bdea505471b7bcb1203497a0ea106461fb7e2c5af6c3 |
Hashes for polyglot_translator-2.2.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3c4e27e9e7bbfabb666cb1fe6f4a2ee4f390a8026c1e4168beb3917df1dfe14f |
|
MD5 | e7911670df0c909ad4b530cd055313ae |
|
BLAKE2b-256 | 07f413db9979a7e139cfc45510677a568397e717a5722d53a3d960882ee1136d |