mirror of
https://github.com/jlu5/SupyPlugins.git
synced 2025-05-07 12:03:43 -05:00
WTE: make output language configurable
This commit is contained in:
parent
c2c3a9c842
commit
bb02058a27
@ -48,9 +48,11 @@ def configure(advanced):
|
||||
|
||||
|
||||
WTE = conf.registerPlugin('WTE')
|
||||
# This is where your configuration variables (if any) should go. For example:
|
||||
# conf.registerGlobalValue(WTE, 'someConfigVariableName',
|
||||
# registry.Boolean(False, _("""Help for someConfigVariableName.""")))
|
||||
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
|
||||
codes as listed at:
|
||||
https://cloud.google.com/translate/v2/using_rest#language-params""")))
|
||||
|
||||
|
||||
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
|
||||
|
@ -66,7 +66,7 @@ class WTE(callbacks.Plugin):
|
||||
'ur', 'pl', 'eo', 'yo', 'en', 'yi')
|
||||
|
||||
def getTranslation(self, irc, sourceLang, targetLang, text):
|
||||
url = "https://translate.google.com/translate_a/t?"+ \
|
||||
url = "http://translate.google.com/translate_a/t?"+ \
|
||||
urlencode({"client": "p",
|
||||
"sl":sourceLang, "tl":targetLang,
|
||||
"q":text})
|
||||
@ -85,10 +85,14 @@ class WTE(callbacks.Plugin):
|
||||
Worst Translations Ever! plugin. Translates <text> through
|
||||
multiple rounds of Google Translate to get amazing results!
|
||||
"""
|
||||
outlang = self.registryValue('language', msg.args[0])
|
||||
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(8,12))
|
||||
for targetlang in ll:
|
||||
text = self.getTranslation(irc, 'en', targetlang, text)
|
||||
text = self.getTranslation(irc, "auto", 'en', text)
|
||||
text = self.getTranslation(irc, outlang, targetlang, text)
|
||||
text = self.getTranslation(irc, "auto", outlang, text)
|
||||
irc.reply(text)
|
||||
wte = wrap(wte, ['text'])
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user