From b51075969f913a29e460f2c5029a26a4a6d1f0db Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Wed, 9 Sep 2015 21:24:47 +0200 Subject: [PATCH] Google: Move the main code of translate to a separate function (usable by other plugins). --- plugins/Google/plugin.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/plugins/Google/plugin.py b/plugins/Google/plugin.py index bc6915184..388bd471e 100644 --- a/plugins/Google/plugin.py +++ b/plugins/Google/plugin.py @@ -240,16 +240,8 @@ class Google(callbacks.PluginRegexp): s = ', '.join([format('%s: %i', bold(s), i) for (i, s) in results]) irc.reply(s) - @internationalizeDocstring - def translate(self, irc, msg, args, sourceLang, targetLang, text): - """ [to] - - Returns translated from into . - """ - - channel = msg.args[0] + def _translate(self, sourceLang, targetLang, text): headers = dict(utils.web.defaultHeaders) headers['User-Agent'] = ('Mozilla/5.0 (X11; U; Linux i686) ' 'Gecko/20071127 Firefox/2.0.0.11') @@ -275,7 +267,18 @@ class Google(callbacks.PluginRegexp): except: language = 'unknown' - irc.reply(''.join(x[0] for x in data[0]), language) + return (''.join(x[0] for x in data[0]), language) + + @internationalizeDocstring + def translate(self, irc, msg, args, sourceLang, targetLang, text): + """ [to] + + Returns translated from into . + """ + channel = msg.args[0] + (text, language) = self._translate(sourceLang, targetLang, text) + irc.reply(text, language) translate = wrap(translate, ['something', 'to', 'something', 'text']) def googleSnarfer(self, irc, msg, match):