mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-30 06:49:24 +01:00
add detected source language display for 'auto' google translate, add test for auto translate.
This commit is contained in:
parent
6b324674a7
commit
ca045128d7
@ -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):
|
||||
|
@ -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+')
|
||||
|
Loading…
Reference in New Issue
Block a user