DeepL CLI
DeepL CLI is a fast and lightweight command-line tool for the DeepL API, written in Crystal.
- Supports document translation
pdf,docx,txt, etc. - Supports glossaries
- Precompiled binaries available
Installation
Download
- Download the binary from the Releases
Homebrew
Proxy settings (optional)
export HTTPS_PROXY=https://[IP]:[port]
Prerequisites
You will need an API key for DeepL. Create one here and set it as an environment variable:
Usage
Translate text
Options:
-f, --from [LANG] Source language [AUTO]
-t, --to [LANG] Target language [EN]
-p, --paste Input text from clipboard
-g, --glossary NAME Glossary name
-F, --formality OPT Formality (default more less)
-C, --context TEXT Context (experimental)
-S, --split-sentences OPT Split sentences
-A, --ansi Do not remove ANSI escape codes
Note: ANSI escape sequences are removed by default.
Translate documents
To translate a document, use the doc subcommand:
Options for document translation:
-t, --to [LANG] Target language [EN]
-g, --glossary NAME Glossary name
-F, --formality OPT Formality (default more less)
-o, --output FILE Output file
-O, --output-format FORMAT Output file format
Supported file formats.
docx- Microsoft Word Documentpptx- Microsoft PowerPoint Documentxlsx- Microsoft Excel Documentpdf- Portable Document Formathtm/html- HTML Documenttxt- Plain Text Documentxlf/xliff- XLIFF Document, version 2.1
Manage glossaries
For glossary management, use the glossary subcommand:
Options for glossary management:
create Create a glossary
delete Delete glossaries
edit Edit glossaries
view View glossaries
-l, --list List glossaries
Improve text (Rephrase)
Use the rephrase subcommand to rewrite text in different styles or tones.
Options for rephrase:
-s, --writing-style STYLE academic business casual default simple
-t, --tone TONE confident diplomatic enthusiastic friendly
Examples
Below are examples for translating text, translating documents, and working with glossaries.
Translate text
To translate the text "Hola mundo" from Spanish (ES) to English (EN):
Or, using standard input:
Standard input translation is useful for quick references.
The man command can also be translated (by removing ANSI escape sequences):
To translate multiple lines, press Ctrl+D when you have finished typing. This is particularly useful when copying and pasting from the clipboard.
# Hola
# mundo
# Ctrl + D
Translate text from the clipboard:
You can also pass a text file as an argument:
It's possible to pass multiple text files:
If you are translating multiple files, you might want to add the filename to the header:
To use a glossary for translation:
To refer to the original text, you can use tee dev/stderr:
Translate Documents
You can directly translate documents:
# The translated document will be saved as your_PT.pdf
To use a glossary for translation:
To translate a PDF document and save it in docx format:
deepl doc input.pdf -O docx -o output.docx
To translate multiple files, use Unix commands such as find, xargs, fd:
Glossaries
The DeepL API supports glossaries. See here for the format of the glossary file. The Glossary API has been migrated to version 3.
To create a glossary:
To list glossaries:
To list only the names of the glossary:
To use a glossary for text translation:
To use a glossary for document translation:
To display the contents of the glossary:
Rephrase
Change writing style:
# Expressions of gratitude are extended.
Change tone:
# Thank you so much! I really appreciate it.
Information
To display a list of available source languages:
To display a list of available target languages:
To output usage information:
# https://api.deepl.com/v2
# character_count: 614842
# character_limit: 1000000000000
Environment Variables
| Name | Description |
|---|---|
| DEEPL_AUTH_KEY | DeepL API authentication key |
| DEEPL_TARGET_LANG | Default target language |
| DEEPL_USER_AGENT | User-Agent |
| EDITOR | Text editor for editing glossary |
DeepL CLI automatically detects the target language, but if this does not work, the environment variable DEEPL_TARGET_LANG can be set.
Contributing
- Fork this repository
- Report bugs
- Fix bugs and submit pull requests
- Write, clarify, or fix documentation
- Suggest or add new features
Development
Compilation from source code
cd deepl-cli
shards build --release
A compiled binary file will be created in the bin directory. Installation is simply copying the generated binary.
sudo cp bin/deepl /usr/local/bin
If you encounter a bug, follow the command with the -d option and run it. You can view the backtrace.
DeepL API Library
License
This project is licensed under the MIT License.
Happy translating!