diff options
author | Sean B. Palmer <http://inamidst.com/sbp/> | 2008-02-23 12:16:43 +0000 |
---|---|---|
committer | Sean B. Palmer <http://inamidst.com/sbp/> | 2008-02-23 12:16:43 +0000 |
commit | 2fb00589439a4efb3906d4e681e7ed815dcd180a (patch) | |
tree | 0a6b0ff1a4b5697fc7c3cb0aa3dc934246fcb874 /modules/translate.py | |
parent | 7931fab14599b739c18c8f1ebcc24b75688dbc09 (diff) | |
download | bot-2fb00589439a4efb3906d4e681e7ed815dcd180a.tar.gz bot-2fb00589439a4efb3906d4e681e7ed815dcd180a.tar.bz2 bot-2fb00589439a4efb3906d4e681e7ed815dcd180a.zip |
Lots of fixes, changes, and new goodies.
Diffstat (limited to 'modules/translate.py')
-rw-r--r-- | modules/translate.py | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/modules/translate.py b/modules/translate.py index ed3589f..7e14b1d 100644 --- a/modules/translate.py +++ b/modules/translate.py @@ -67,21 +67,24 @@ def translate(phrase, lang, target='en'): return None def tr(phenny, input): + """Translates a phrase, with an optional language hint.""" lang, phrase = input.groups() - + phrase = phrase.encode('utf-8') if (len(phrase) > 350) and (not phenny.admin(input.nick)): return phenny.reply('Phrase must be under 350 characters.') language = guess_language(phrase) if language is None: return phenny.reply('Unable to guess the language, sorry.') + else: language = lang.encode('utf-8') if language != 'en': translation = translate(phrase, language) if translation is not None: - return phenny.reply(u'"%s" (%s)' % (translation, language)) + translation = translation.decode('utf-8').encode('utf-8') + return phenny.reply('"%s" (%s)' % (translation, language)) - error = "I think it's %s, but I can't translate that language." + error = "I think it's %s, which I can't translate." return phenny.reply(error % language.title()) # Otherwise, it's English, so mangle it for fun @@ -93,10 +96,11 @@ def tr(phenny, input): return phenny.reply(u'"%s" (en-unmangled)' % phrase) return phenny.reply("I think it's English already.") # @@ or 'Why but that be English, sire.' -tr.doc = ('phenny: "<phrase>"? or phenny: <lang> "<phrase>"?', - 'Translate <phrase>, optionally forcing the <lang> interpretation.') tr.rule = ('$nick', ur'(?:([a-z]{2}) +)?["“](.+?)["”]\? *$') +tr.example = '$nickname: "mon chien"? or $nickname: fr "mon chien"?' tr.priority = 'low' +# @@ mangle + if __name__ == '__main__': print __doc__.strip() |