pythonglossarydeepl

Python DeepL API glossary not working for translation


I am using the DeepL API to translate text and I also want to include a glossary for translating.

Creating the glossary worked fine, I can see all the correct entries but translating with the glossary brings up some weird behaviors:

  1. One entry is I:Ich because DeepL doesn't seem to be able to translate the english "I" to the german "Ich" (always returns "I" in German), so I thought I can fix this with the glossary but the API is still returning "I" for "I" even though I added the glossary in the request.

  2. DeepL does not always seem to take the exact value from the glossary. E.g. I have an entry "holding,halten". Deepl translates "holding" without the glossary included to "Betrieb" but when adding the glossary it returns "haltend". So it is adding a "d" at the end.

What am I not getting here? Deepl support is not answering. Happy for every help.

This is the function I use to translate text:

def translate_text_with_deepl(text_to_translate):
    URL = "https://api-free.deepl.com/v2/translate"
    params = {
        "auth_key": DEEPL_APY_KEY,
        "text": text_to_translate,
        "target_lang": TARGET_LANGUAGE_CODE,
        "source_lang": SOURCE_LANGUAGE_CODE,
        "glossary_id": GLOSSARY_ID,
        
    }
    re = requests.post(URL, params)
    return re.json()["translations"][0]["text"]

Solution

  • As per the Official DeepL Support:

    DeepL API Glossary is not suited for this project because the glossary feature needs context to perform properly. One word translations would be a 1:1 replacement which is not supported.