Skip to content

About

Keep product names and other terms untranslated in every target language with the DeepL API

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

Keep terms untranslated with the DeepL API

Some words should never be translated: product names, brand names, model numbers, internal terminology. A glossary can map a term to itself, but you need a dictionary entry for every language pair, which gets cumbersome when you have thousands of terms and many target languages.

This example shows a language-independent alternative. You keep a single do-not-translate list, and the DeepL API leaves those terms unchanged in every target language.

How it works

  1. The plain text is escaped so it can be sent as HTML.
  2. Every protected term is wrapped in <span translate="no">…</span>.
  3. The text is translated with tag_handling="html". DeepL leaves the contents of translate="no" elements untouched (docs).
  4. The spans are removed, and you get plain text back.
Input:   Sign in to FlowDesk with your company account.
Sent:    Sign in to <span translate="no">FlowDesk</span> with your company account.
Output:  Connectez-vous à FlowDesk avec votre compte d'entreprise.

Quick start

pip install deepl
export DEEPL_AUTH_KEY=your-key
python protected_terms.py

Use it in your own code

import deepl
from protected_terms import build_term_pattern, translate_with_protected_terms

client = deepl.DeepLClient("your-key")
pattern = build_term_pattern(["FlowDesk", "Power Hub", "Acme X-200"])  # build once, reuse

translations = translate_with_protected_terms(
    client,
    ["Your sensors send their data to Power Hub every minute."],
    target_lang="DE",
    term_pattern=pattern,
)

Any extra keyword arguments (context, formality, glossary and so on) are passed through to translate_text.

Notes

  • Matching: terms are matched case-sensitively and only as whole words. When terms overlap, the longest one wins, so Power Hub Pro takes precedence over Power Hub.
  • Large term lists: load your terms from a file or database and call build_term_pattern once at startup. It compiles a single regular expression for the whole list.
  • Give DeepL context: describe the protected terms in the context parameter (for example, "FlowDesk and Power Hub are product names"). Context is not translated or billed.
  • Already working with XML? Wrap the terms in a custom tag and use tag_handling="xml" with ignore_tags instead (docs).

License

MIT

About

Keep product names and other terms untranslated in every target language with the DeepL API

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages