Python DeepL API术语翻译不起作用

huangapple go评论68阅读模式
英文:

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. For example, 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"]
英文:

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"]

答案1

得分: 0

根据官方DeepL支持:

> DeepL API词汇表不适用于这个项目,因为词汇表功能需要上下文才能正常运行。一词一译将不受支持。

英文:

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.

huangapple
  • 本文由 发表于 2023年3月20日 23:23:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/75792173.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定