英文:
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:
-
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 therequest
. -
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:
-
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 therequest
. -
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论