fix translate module, convert to 4 space tabs
parent
4593a1ae9d
commit
2820bc61d6
|
@ -73,37 +73,40 @@ tr.example = '$nickname: "mon chien"? or $nickname: fr "mon chien"?'
|
||||||
tr.priority = 'low'
|
tr.priority = 'low'
|
||||||
|
|
||||||
def tr2(phenny, input):
|
def tr2(phenny, input):
|
||||||
"""Translates a phrase, with an optional language hint."""
|
"""Translates a phrase, with an optional language hint."""
|
||||||
command = input.group(2).encode('utf-8')
|
command = input.group(2)
|
||||||
|
if not command:
|
||||||
|
phenny.reply("Please provide a phrase to translate")
|
||||||
|
return
|
||||||
|
|
||||||
def langcode(p):
|
def langcode(p):
|
||||||
return p.startswith(':') and (2 < len(p) < 10) and p[1:].isalpha()
|
return p.startswith(':') and (2 < len(p) < 10) and p[1:].isalpha()
|
||||||
|
|
||||||
args = ['auto', 'en']
|
args = ['auto', 'en']
|
||||||
|
|
||||||
for i in xrange(2):
|
for i in range(2):
|
||||||
if not ' ' in command: break
|
if not ' ' in command: break
|
||||||
prefix, cmd = command.split(' ', 1)
|
prefix, cmd = command.split(' ', 1)
|
||||||
if langcode(prefix):
|
if langcode(prefix):
|
||||||
args[i] = prefix[1:]
|
args[i] = prefix[1:]
|
||||||
command = cmd
|
command = cmd
|
||||||
phrase = command
|
phrase = command.encode('utf-8')
|
||||||
|
|
||||||
if (len(phrase) > 350) and (not input.admin):
|
if (len(phrase) > 350) and (not input.admin):
|
||||||
return phenny.reply('Phrase must be under 350 characters.')
|
return phenny.reply('Phrase must be under 350 characters.')
|
||||||
|
|
||||||
src, dest = args
|
src, dest = args
|
||||||
if src != dest:
|
if src != dest:
|
||||||
msg, src = translate(phrase, src, dest)
|
msg, src = translate(phrase, src, dest)
|
||||||
if isinstance(msg, str):
|
#if isinstance(msg, str):
|
||||||
msg = msg.decode('utf-8')
|
# msg = msg.decode('utf-8')
|
||||||
if msg:
|
if msg:
|
||||||
msg = web.decode(msg) # msg.replace(''', "'")
|
msg = web.decode(msg) # msg.replace(''', "'")
|
||||||
msg = '"%s" (%s to %s, translate.google.com)' % (msg, src, dest)
|
msg = '"%s" (%s to %s, translate.google.com)' % (msg, src, dest)
|
||||||
else: msg = 'The %s to %s translation failed, sorry!' % (src, dest)
|
else: msg = 'The %s to %s translation failed, sorry!' % (src, dest)
|
||||||
|
|
||||||
phenny.reply(msg)
|
phenny.reply(msg)
|
||||||
else: phenny.reply('Language guessing failed, so try suggesting one!')
|
else: phenny.reply('Language guessing failed, so try suggesting one!')
|
||||||
|
|
||||||
tr2.commands = ['tr']
|
tr2.commands = ['tr']
|
||||||
tr2.priority = 'low'
|
tr2.priority = 'low'
|
||||||
|
|
Loading…
Reference in New Issue