DeepLcom / deepl-php

Official PHP library for the DeepL language translation API.
MIT License
202 stars 23 forks source link

Use glossary for target language en-GB #16

Closed SarahTrees closed 1 year ago

SarahTrees commented 1 year ago

QUEST: With which parameters do I have to create a glossary for DE->EN so that I can use it for translation?


When creating a glossary, the target language is changed from "en-GB" to "en". Translator.php::331 This means that it is only possible to create a glossary for e.g. "de"->"en".


When using Translator::translateText for the target language "en" you get an error message: Fatal error: Uncaught DeepL\DeepLException: targetLang="en" is deprecated, please use "en-GB".

Therefore, you must use Translator::translateText with "en-GB". This will give results when using WITHOUT glossary.

When using the previously created glossary with target language "en" the library sends these post parameters to the API: target_lang=en-GB&source_lang=en&formality=prefer_more&glossary_id=500ebda5-50b5-4e6b-ae0e-b8d64bcf57b3&text=Example+Sentence&tag_handling=html you get the error message: {"message": "Language pair of the glossary doesn't match the language pair of the request"}

daniel-jones-deepl commented 1 year ago

Hi @SarahTrees, thanks for the question. You are right, glossary target languages are not variant-specific and work for any language variant, i.e. a * -> "en" glossary works for both target language variants "en-GB" and "en-US".

When you use a glossary with translateText, you need to specify the source language and it has to match the glossary. In your case it looks like the source language is specified as "en"; try changing it to "de" to fix your problem.

SarahTrees commented 1 year ago

Thank you very much! That was exactly the bug in the end. It's good to know that DeepL also produces useful results when the source-L is not correct - without a glossary.