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
-
docx (Microsoft Word)
-
pptx (Microsoft PowerPoint)
-
html
-
htm
-
raw text files like .txt or .dat
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.
Optional: add Polyglot to PATH
I suggest you to update your PATH in order to call the command faster.
export PATH=$PATH:$HOME/.local/bin
⚠️This command can be different depending on your OS.
Now you can run Polyglot simply with:
polyglot
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 file, it returns both a PO and an MO file.
Command options
Option | Required | Description |
---|---|---|
-p, --source_file | yes | The file to be translated. |
-t, --target_lang | yes | the code of the language into which you want to translate the source file |
-o, --output_directory | no | The directory where the output file will be located. Will be used the working directory if this option is invalid or not used. |
-s, --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.
polyglot translate -p en.json -t 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.
polyglot translate -p en.po -t JA -o $HOME -s EN
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.
polyglot set_license
Print usage info
It returns DeepL usage info related to your API key, run with:
polyglot print_usage_info
Print supported languages
It returns the list of languages currently supported by DeepL, run with:
polyglot print_supported_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.1.4.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 41b06ddcf207cc6eaa061b31955678b8c5016652c16e3004a55fc75a81bf2507 |
|
MD5 | 1c40e288749b10ad2931d3d6d1eb04d9 |
|
BLAKE2b-256 | 570d84b87f946997e7222e6dbaa9bcc95f64d19238f3b0466af2dbca44192c66 |
Hashes for polyglot_translator-2.1.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 29c8bb78d7a7fe59256fc30e913ccbb524883560500257a221585b02f033af3c |
|
MD5 | 8d6b4ad6159acb6b5b1854a25f87865a |
|
BLAKE2b-256 | a1561177a85e4c2f42dc1ba90a9ace7f18fd0f493469b7489463f5e335e25238 |