WTE: be more verbose in output

This commit is contained in:
GLolol 2014-12-04 15:57:44 -08:00
parent ea03b40137
commit b77e6129fe
2 changed files with 11 additions and 0 deletions

View File

@ -48,6 +48,9 @@ def configure(advanced):
WTE = conf.registerPlugin('WTE')
conf.registerChannelValue(WTE, 'verbose',
registry.Boolean(False, _("""Determines whether
verbose output (list of languages used, etc.) will be used.""")))
conf.registerChannelValue(WTE, 'language',
registry.String('en', _("""Determines what the output language
of 'wte' will be. This should be one of Google Translate's language

View File

@ -86,6 +86,7 @@ class WTE(callbacks.Plugin):
args['q'] = text
url = "http://translate.google.com/translate_a/t?"+ \
urlencode(args)
self.log.debug("WTE: Using URL %s" % url)
try:
data = json.loads(utils.web.getUrl(url).decode("utf-8"))
except utils.web.Error as e:
@ -102,10 +103,13 @@ class WTE(callbacks.Plugin):
multiple rounds of Google Translate to get amazing results!
"""
outlang = self.registryValue('language', msg.args[0])
inp = text
if outlang not in self.langs:
irc.error("Unrecognized output language. Please set "
"'config plugins.wte.language' correctly.", Raise=True)
ll = random.sample(self.langs, random.randint(6,12))
self.log.debug(format("WTE: Using %i languages: %L "
"(outlang %s)", len(ll), ll, outlang))
for targetlang in ll:
text = self.getTranslation(irc, "auto", targetlang, text)
text = self.getTranslation(irc, "auto", outlang, text)
@ -117,6 +121,10 @@ class WTE(callbacks.Plugin):
"are some lingering issues handling Unicode on "
"versions of Python 2.")
irc.error(s, Raise=True)
if self.registryValue("verbose", msg.args[0]):
irc.reply(format("Translated through \x02%i\x02 languages: %L "
"(outlang %s)",
len(ll), ll, outlang))
irc.reply(text)
wte = wrap(wte, ['text'])