mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-17 23:52:46 +01:00
add detected source language display for 'auto' google translate, add test for auto translate.
This commit is contained in:
parent
b8f8cec6f5
commit
34cab7f4c9
@ -276,7 +276,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):
|
||||
|
@ -59,6 +59,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