DeepLcom / deepl-python

Official Python library for the DeepL language translation API.
https://www.deepl.com
MIT License
1.11k stars 80 forks source link

Catching No Translations #67

Closed johnbumgarner closed 1 year ago

johnbumgarner commented 1 year ago

I'm trying to catch some type of error when there is no translation.

For example I'm trying to pass a junk word - 'madrdogesssss' in Spanish for translation to English. deepl returns 'madrdogesssss', which isn't a translation, because there is no translation available.

import deepl
from deepl.exceptions import AuthorizationException
from deepl.exceptions import QuotaExceededException
from deepl.exceptions import TooManyRequestsException

        try:
            translator = deepl.Translator(auth_key=self._api_key)
            result = translator.translate_text(self._str_to_translate,
                                               target_lang=self._source_language,
                                               source_lang='EN')
            translated_text = result.text
            return translated_text

truncated...
johnbumgarner commented 1 year ago

After checking https://www.deepl.com/en/translatorfor the same nonsensual word, I noted that it returns more nonsensual words. So nonsensual translations are a feature.