deepl-cli
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinesedeepl-cli
deepl-cli
CLI tool for translating text using the DeepL API. Pipe-friendly, supports context and formality options.
一款调用DeepL API进行文本翻译的CLI工具。支持管道操作,可配置上下文和语体风格选项。
Prerequisites
前置要求
- Node.js >= 18
- A DeepL API key (free tier: 500,000 characters/month)
- Node.js >= 18
- 一个DeepL API密钥(免费额度:每月500,000字符)
Installation
安装
bash
npm install -g @daliusd/deepl-clibash
npm install -g @daliusd/deepl-cliConfiguration
配置
Create :
~/.config/deepl-cli/config.jsonbash
mkdir -p ~/.config/deepl-cliOption A -- Static API key:
json
{
"api_key": "your-deepl-api-key"
}Option B -- Command-based key (for password managers like , 1Password CLI, etc.):
passjson
{
"api_key_command": "pass show deepl-api-key"
}If both are present, takes precedence.
api_key_command创建:
~/.config/deepl-cli/config.jsonbash
mkdir -p ~/.config/deepl-cli选项A -- 静态API密钥:
json
{
"api_key": "your-deepl-api-key"
}选项B -- 命令式密钥(适用于、1Password CLI等密码管理器):
passjson
{
"api_key_command": "pass show deepl-api-key"
}如果同时配置了两者,优先级更高。
api_key_commandCommands
命令
All translation is done via a single command:
deepl-cli [options] [text]所有翻译操作都通过单个命令完成:
deepl-cli [options] [text]Basic Translation
基础翻译
bash
deepl-cli -t de "Hello, world!"bash
deepl-cli -t de "Hello, world!"Specify Source Language
指定源语言
bash
deepl-cli -t de -s en "Hello"By default the source language is auto-detected. Use only when auto-detection is insufficient.
-sbash
deepl-cli -t de -s en "Hello"默认会自动检测源语言。仅当自动检测结果不准确时才需要使用参数。
-sContext-Aware Translation
上下文感知翻译
Context influences the translation but is not itself translated or billed:
bash
deepl-cli -t de -c "This is a greeting in a formal business email" "Hello"上下文会影响翻译结果,但本身不会被翻译或计入计费字符:
bash
deepl-cli -t de -c "This is a greeting in a formal business email" "Hello"Formality Control
语体风格控制
bash
undefinedbash
undefinedFormal
正式语体
deepl-cli -t de -f more "How are you?"
deepl-cli -t de -f more "How are you?"
Informal
非正式语体
deepl-cli -t de -f less "How are you?"
Valid formality values: `less`, `more`, `default`, `prefer_less`, `prefer_more`.deepl-cli -t de -f less "How are you?"
有效的语体风格值:`less`、`more`、`default`、`prefer_less`、`prefer_more`。Piped Input
管道输入
bash
echo "Hello, world!" | deepl-cli -t deTranslated text goes to stdout with no extra formatting, making it pipeline-friendly:
bash
echo "Hello" | deepl-cli -t de | pbcopybash
echo "Hello, world!" | deepl-cli -t de翻译后的文本会输出到标准输出(stdout),无额外格式,便于在管道中使用:
bash
echo "Hello" | deepl-cli -t de | pbcopyVerbose Mode
详细模式
Metadata is written to stderr so stdout remains clean:
bash
deepl-cli -t de -v "Hello, world!"元数据会写入标准错误输出(stderr),确保标准输出(stdout)内容纯净:
bash
deepl-cli -t de -v "Hello, world!"stdout: Hallo, Welt!
stdout: Hallo, Welt!
stderr: Detected source language: en
stderr: Detected source language: en
stderr: Billed characters: 13
stderr: Billed characters: 13
undefinedundefinedOptions Reference
选项参考
| Option | Short | Description |
|---|---|---|
| | Target language code (required, e.g. |
| | Source language code (default: auto-detect) |
| | Additional context for translation (not translated, not billed) |
| | Formality: |
| | Show metadata (detected source language, billed characters) |
| | Show help |
| Show version |
| 选项 | 简写 | 描述 |
|---|---|---|
| | 目标语言代码(必填,例如 |
| | 源语言代码(默认:自动检测) |
| | 翻译的额外上下文(不会被翻译,不计入计费) |
| | 语体风格: |
| | 显示元数据(检测到的源语言、计费字符数) |
| | 显示帮助信息 |
| 显示版本号 |
Common Language Codes
常用语言代码
Language codes are case-insensitive and follow ISO 639-1.
Source languages (or omit for auto-detection):
| Code | Language |
|---|---|
| English |
| German |
| French |
| Spanish |
| Italian |
| Japanese |
| Chinese |
| Polish |
| Dutch |
| Portuguese |
| Russian |
Target languages (some include regional variants):
| Code | Language |
|---|---|
| English (American) |
| English (British) |
| German |
| French |
| Spanish |
| Italian |
| Japanese |
| Chinese (Simplified) |
| Chinese (Traditional) |
| Polish |
| Dutch |
| Portuguese (Brazilian) |
| Portuguese (European) |
| Russian |
See the DeepL API documentation for the full list.
语言代码不区分大小写,遵循ISO 639-1标准。
源语言(或留空以自动检测):
| 代码 | 语言 |
|---|---|
| 英语 |
| 德语 |
| 法语 |
| 西班牙语 |
| 意大利语 |
| 日语 |
| 中文 |
| 波兰语 |
| 荷兰语 |
| 葡萄牙语 |
| 俄语 |
目标语言(部分包含区域变体):
| 代码 | 语言 |
|---|---|
| 英语(美式) |
| 英语(英式) |
| 德语 |
| 法语 |
| 西班牙语 |
| 意大利语 |
| 日语 |
| 中文(简体) |
| 中文(繁体) |
| 波兰语 |
| 荷兰语 |
| 葡萄牙语(巴西) |
| 葡萄牙语(欧洲) |
| 俄语 |
完整列表请查看DeepL API文档。
Tips
小贴士
- No arguments or shows usage information.
--help - Multiple words as positional arguments are joined with a space: translates "Hello world".
deepl-cli -t de Hello world - Verbose mode writes metadata to stderr, so piping stdout is always safe.
- is recommended over
api_key_commandto avoid storing secrets in plain text.api_key
- 不带参数或使用会显示使用说明。
--help - 多个单词作为位置参数时会自动用空格连接:会翻译“Hello world”。
deepl-cli -t de Hello world - 详细模式会将元数据写入stderr,因此管道传输stdout始终是安全的。
- 推荐使用而非
api_key_command,避免以明文形式存储密钥。api_key