DeepL Translate
Guardrails & Data Flow
- When to call: Use DeepL only on explicit request or high-stakes ambiguity; proper names, jargon, idioms, or less-familiar pairs are cues to assess uncertainty, not automatic triggers.
- External data & secrets:
translate.mjsreadsDEEPL_API_KEYand sends text over HTTPS to DeepL (api-free.deepl.comby default;DEEPL_API_HOST=api.deepl.combare hostname withouthttps://for Pro keys). Send only content authorized for external processing, and never print or embed the API key in text or command output. - Critical verification: Treat DeepL output as another candidate translation, not proof of correctness. Reconcile discrepancies against source context or official terminology and flag remaining ambiguity.
1. Check Credentials
Verify key presence without printing its value:
# Bash
if [ -n "${DEEPL_API_KEY//[[:space:]]/}" ]; then echo "DEEPL_API_KEY is set"; else echo "DEEPL_API_KEY is missing"; fi
# PowerShell
if ([string]::IsNullOrWhiteSpace($env:DEEPL_API_KEY)) { 'DEEPL_API_KEY is missing' } else { 'DEEPL_API_KEY is set' }
If missing, stop and instruct the user to set DEEPL_API_KEY (export DEEPL_API_KEY="..." or $env:DEEPL_API_KEY = "..."; persistent shell config is optional).
2. Translate
Requires Node 18+. Replace {SKILL_DIR} with this skill's installed directory and quote paths:
node "{SKILL_DIR}/translate.mjs" --target ZH-HANS --text "The plaintiff filed a motion to compel discovery."
node "{SKILL_DIR}/translate.mjs" --source JA --target EN-US --text "持分会社"
- Pass the text itself with
--textor-t. To translate a literal flag, use an attached value such as--text=-tor--text=--help. Whitespace-only input is rejected before sending. Other text goes to DeepL with its original spacing. - Set
--target/--target-langto the requested language. Omit--source/--source-langfor auto-detection. - Output & timeout: Stdout outputs only the translation with paragraphs preserved; failures print
ERROR:to stderr and exit non-zero. Requests time out at 60s (respect shorter task deadlines). - Optional
--glossary 'term=translation;term=translation': Performs literal, case-sensitive substring replacement on DeepL's output (not DeepL's Glossary API). Example:API=接口also rewritesAPIs. Avoid;inside terms; pairs without=are skipped with a stderr warning.
3. Language Codes & Error Triage
- Targets: Follow the user's requested locale; common precise codes include
ZH-HANS,ZH-HANT,EN-US,EN-GB,PT-BR,PT-PT. - Uncertain language support: Do not rely on an outdated static list — query
GET https://<host>/v3/languages?resource=translate_textwithAuthorization: DeepL-Auth-Key <key>(resourceis required; entries distinguishusable_as_source/usable_as_target, returning BCP 47 codes whiletranslate.mjsalso accepts uppercase). Text translation calls/v2/translate. Branch on HTTP status, not exact error wording (supported languages).
| Error | Action |
|---|---|
403 |
Check DEEPL_API_KEY, DEEPL_API_HOST (Free vs Pro), and key permission scope. |
456 |
Quota, Cost Control, or key-level limit reached — check the DeepL console. |
400 / unsupported language |
Check the API error body, target variant, and live /v3/languages support. |
| Timeout / network error | Check connectivity and DEEPL_API_HOST before retrying. |
