New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

when translation fails #76

Closed
az0 opened this Issue Jan 9, 2015 · 3 comments

Comments

Projects
None yet
3 participants
@az0

az0 commented Jan 9, 2015

Would you please test and document the behavior when translation fails, such as when the language is not supported (distinct from an HTTP error)?

Example (Cherokee):

from textblob import TextBlob
txt=u'    Ꭰ Ꭱ Ꭲ Ꭳ Ꭴ Ꭵ Ꭶ Ꭷ Ꭸ Ꭹ Ꭺ Ꭻ Ꭼ Ꭽ Ꭾ Ꭿ Ꮀ Ꮁ Ꮂ Ꮃ Ꮄ Ꮅ Ꮆ Ꮇ Ꮈ Ꮉ Ꮊ Ꮋ Ꮌ Ꮍ Ꮎ Ꮏ Ꮐ Ꮑ Ꮒ Ꮓ Ꮔ Ꮕ Ꮖ Ꮗ Ꮘ Ꮙ Ꮚ Ꮛ Ꮜ Ꮝ Ꮞ Ꮟ Ꮠ Ꮡ Ꮢ Ꮣ Ꮤ Ꮥ Ꮦ Ꮧ Ꮨ Ꮩ Ꮪ Ꮫ Ꮬ Ꮭ Ꮮ Ꮯ Ꮰ Ꮱ Ꮲ Ꮳ Ꮴ Ꮵ Ꮶ Ꮷ Ꮸ Ꮹ Ꮺ Ꮻ Ꮼ Ꮽ Ꮾ Ꮿ Ᏸ Ᏹ Ᏺ Ᏻ Ᏼ '
bl=TextBlob(txt)
bl_en=bl.translate(to='en')
@sloria

This comment has been minimized.

Owner

sloria commented Jun 10, 2015

TextBlob will return whatever result is returned by the Google Translator. There really currently no way to detect whether language of the source text is unsupported.

@sloria sloria closed this Jun 10, 2015

@jschnurr

This comment has been minimized.

Collaborator

jschnurr commented Jun 10, 2015

If the translation is unsuccessful, the original string is returned, with whitespace removed:

>>> translator.translate(u'        Ꭰ Ꭱ Ꭲ Ꭳ Ꭴ Ꭵ     ', to_lang='en')
Ꭰ Ꭱ Ꭲ Ꭳ Ꭴ Ꭵ

However, the JSON response from the API includes both the original and translated string. If they match, we could infer that the translation was not successful.

{
   "sentences":[
      {
         "trans":"Ꭰ Ꭱ Ꭲ Ꭳ Ꭴ Ꭵ",
         "orig":"Ꭰ Ꭱ Ꭲ Ꭳ Ꭴ Ꭵ",
         "translit":"",
         "src_translit":""
      }
   ],
   "src":"en",
   "server_time":1
}

What would be the desired behavior in that case - return None?

@az0

This comment has been minimized.

az0 commented Jun 10, 2015

Yes, either return None or raise an exception.

Thanks

sloria added a commit that referenced this issue Jul 19, 2015

Merge pull request #88 from jschnurr/translate-failed-76
Fix #76 - when translation fails, raise TranslatorError.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment