Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Google: Remove translate command. Closes GH-337.

  • Loading branch information...
commit d23757e8fa6847633da5539a3af37637b1990c04 1 parent 14cad12
nyuszika7h authored committed
Showing with 0 additions and 64 deletions.
  1. +0 −64 plugins/Google/plugin.py
View
64 plugins/Google/plugin.py
@@ -246,70 +246,6 @@ def fight(self, irc, msg, args):
s = ', '.join([format('%s: %i', bold(s), i) for (i, s) in results])
irc.reply(s)
- _gtranslateUrl='http://ajax.googleapis.com/ajax/services/language/translate'
- @internationalizeDocstring
- def translate(self, irc, msg, args, fromLang, toLang, text):
- """<from-language> [to] <to-language> <text>
-
- Returns <text> translated from <from-language> into <to-language>.
- Beware that translating to or from languages that use multi-byte
- characters may result in some very odd results.
- """
- channel = msg.args[0]
- ref = self.registryValue('referer')
- if not ref:
- ref = 'http://%s/%s' % (dynamic.irc.server,
- dynamic.irc.nick)
- headers = utils.web.defaultHeaders
- headers['Referer'] = ref
- opts = {'q': text, 'v': '1.0'}
- lang = conf.supybot.plugins.Google.defaultLanguage
- if fromLang.capitalize() in lang.transLangs:
- fromLang = lang.transLangs[fromLang.capitalize()]
- elif lang.normalize('lang_'+fromLang)[5:] \
- not in lang.transLangs.values():
- irc.errorInvalid(_('from language'), fromLang,
- format(_('Valid languages are: %L'),
- lang.transLangs.keys()))
- else:
- fromLang = lang.normalize('lang_'+fromLang)[5:]
- if toLang.capitalize() in lang.transLangs:
- toLang = lang.transLangs[toLang.capitalize()]
- elif lang.normalize('lang_'+toLang)[5:] \
- not in lang.transLangs.values():
- irc.errorInvalid(_('to language'), toLang,
- format(_('Valid languages are: %L'),
- lang.transLangs.keys()))
- else:
- toLang = lang.normalize('lang_'+toLang)[5:]
- if fromLang == 'auto':
- fromLang = ''
- if toLang == 'auto':
- irc.error("Destination language cannot be 'auto'.")
- return
- opts['langpair'] = '%s|%s' % (fromLang, toLang)
- fd = utils.web.getUrlFd('%s?%s' % (self._gtranslateUrl,
- urllib.urlencode(opts)),
- headers)
- json = simplejson.load(fd)
- fd.close()
- if json['responseStatus'] != 200:
- raise callbacks.Error, 'Google says: Response Status %s: %s.' % \
- (json['responseStatus'], json['responseDetails'],)
- if fromLang != '':
- irc.reply(json['responseData']['translatedText'].encode('utf-8'))
- else:
- detected_language = json['responseData']['detectedSourceLanguage'].encode('utf-8')
- translation = json['responseData']['translatedText'].encode('utf-8')
- 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, translation)
- irc.reply(responsestring)
- translate = wrap(translate, ['something', 'to', 'something', 'text'])
-
def googleSnarfer(self, irc, msg, match):
r"^google\s+(.*)$"
if not self.registryValue('searchSnarfer', msg.args[0]):
Please sign in to comment.
Something went wrong with that request. Please try again.