add detected source language display for 'auto' google translate, add test for auto translate.

This commit is contained in:
Daniel Folkinshteyn 2010-04-03 23:31:13 -04:00 committed by Valentin Lorentz
parent 6b324674a7
commit ca045128d7
2 changed files with 13 additions and 1 deletions

View File

@ -292,7 +292,18 @@ class Google(callbacks.PluginRegexp):
fd.close()
if json['responseStatus'] != 200:
raise callbacks.Error, 'We broke The Google!'
irc.reply(json['responseData']['translatedText'].encode('utf-8'))
if fromLang != '':
irc.reply(json['responseData']['translatedText'].encode('utf-8'))
else:
detected_language = json['responseData']['detectedSourceLanguage']
try:
long_lang_name = [k for k,v in lang.transLangs.iteritems() if v == detected_language][0]
except IndexError: #just in case google adds langs we don't know about
long_lang_name = detected_language
responsestring = "(Detected source language: %s) %s" % \
(long_lang_name,
json['responseData']['translatedText'].encode('utf-8'))
irc.reply(responsestring)
translate = wrap(translate, ['something', 'to', 'something', 'text'])
def googleSnarfer(self, irc, msg, match):

View File

@ -61,6 +61,7 @@ class GoogleTestCase(ChannelPluginTestCase):
def testTranslate(self):
self.assertRegexp('translate en es hello world', 'mundo')
self.assertRegexp('translate auto en ciao', 'Italian.*hello')
def testCalcDoesNotHaveExtraSpaces(self):
self.assertNotRegexp('google calc 1000^2', r'\s+,\s+')