mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-26 20:59:27 +01:00
Google: Move the main code of translate to a separate function (usable by other plugins).
This commit is contained in:
parent
aa13ac88ea
commit
b51075969f
@ -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):
|
||||
"""<source language> [to] <target language> <text>
|
||||
|
||||
Returns <text> translated from <source language> into <target
|
||||
language>.
|
||||
"""
|
||||
|
||||
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):
|
||||
"""<source language> [to] <target language> <text>
|
||||
|
||||
Returns <text> translated from <source language> into <target
|
||||
language>.
|
||||
"""
|
||||
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):
|
||||
|
Loading…
Reference in New Issue
Block a user