DeepL CLI

build

A simple command-line tool for the DeepL API, written in Crystal.

Installation

Download

Homebrew (macOS)

brew install kojix2/brew/deepl-cli

Proxy settings (optional)

export HTTP_PROXY=http://[IP]:[port]
export HTTPS_PROXY=https://[IP]:[port]

Prerequisites

Create a API key for DeepL, then set it as an environment variable:

export DEEPL_AUTH_KEY=your_api_key_here

Usage

deepl [options] <file>

Translate Text

deepl [options] <file>
    -i, --input TEXT                 Input text
    -f, --from [LANG]                Source language [AUTO]
    -t, --to [LANG]                  Target language [EN]
    -g, --glossary ID                Glossary ID
    -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 that since this tool is used on a terminal, ANSI escape sequences are removed by default.

Translate Document

To translate a document, use the doc subcommand:

deepl doc [options] <file>
    -f, --from [LANG]                Source language [AUTO]
    -t, --to [LANG]                  Target language [EN]
    -g, --glossary ID                Glossary ID
    -F, --formality OPT              Formality (default more less)
    -o, --output FILE                Output file
    -O, --output-format FORMAT       Output file format

Manage Glossaries

For glossary management, use the glossary subcommand:

deepl glossary [options]
    list                             List glossaries
    create                           Create glossary
    delete                           Delete glossary
    view                             View glossary
    -l, --list                       List glossaries (short form)
    -p, --language-pairs             List language pairs

Examples

Text translation

To translate the text "Hola mundo" from Spanish (ES) to English (EN):

deepl -i "Hola mundo" -t EN        # Hello world

From standard stream:

echo "Hola mundo" | deepl -t en    # Hello world

Translation from standard input is useful for viewing help:

git --help | deepl -t fr | less
man git | deepl -t de | less

Multiple lines: Press Ctrl+D when finished typing. This is especially useful when copy-pasting from the clipboard.

deepl -f es
# Hola
# mundo
# Ctrl + D

Translate document

You can translate documents directly:

deepl doc your.pdf -t EN
# Save to your_EN.pdf

Translation of multiple documents:

find . -name "*.pdf" -exec deepl doc -t ja {} +
ls -1 *.docx | xargs -L1 deepl doc -t ko
fd -e pdf -e docx -x deepl doc -t zh

Glossaries

Create a glossary:

deepl glossary create -n mydic -f en -t ja mydict.tsv

List glossaries:

deepl glossary list
# deepl glossary -l

Using glossary for translation:

deepl -g mydict
deepl doc -g mydict

Display the contents of the glossary:

deepl glossary view -n mydict

List of languages in which Glossary can be created:

deepl glossary -p

Information

Display a list of available languages (from)

deepl -f

Display a list of available languages (to)

deepl -t

Output usage information

deepl -u

# https://api.deepl.com/v2
# character_count: 614842
# character_limit: 1000000000000

Development

Contributing

  1. Fork this repository
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Compilation from source code

git clone https://github.com/kojix2/deepl-cli
cd deepl-cli
shards build --release
# sudo cp bin/deepl /usr/local/bin

A compiled binary file will be created in the bin directory.

DeepL API Library

License

This project is licensed under the MIT License.

Happy translating!