Some more little fixes, and added a Makefile.
This commit is contained in:
@@ -8,7 +8,7 @@ Licensed under the Eiffel Forum License 2.
|
||||
http://inamidst.com/phenny/
|
||||
"""
|
||||
|
||||
import re
|
||||
import re, time
|
||||
import web
|
||||
|
||||
r_translation = re.compile(r'<div style=padding:10px;>([^<]+)</div>')
|
||||
@@ -43,7 +43,7 @@ def guess_language(phrase):
|
||||
try: return languages[lang]
|
||||
except KeyError:
|
||||
return lang
|
||||
return 'unknown'
|
||||
return 'Moon Language'
|
||||
|
||||
def translate(phrase, lang, target='en'):
|
||||
babelfish = 'http://world.altavista.com/tr'
|
||||
@@ -68,35 +68,40 @@ def translate(phrase, lang, target='en'):
|
||||
|
||||
def tr(phenny, input):
|
||||
"""Translates a phrase, with an optional language hint."""
|
||||
lang, phrase = input.groups()
|
||||
input, output, 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:
|
||||
input = input or guess_language(phrase)
|
||||
if not input:
|
||||
return phenny.reply('Unable to guess the language, sorry.')
|
||||
else: language = lang.encode('utf-8')
|
||||
input = input.encode('utf-8')
|
||||
output = (output or 'en').encode('utf-8')
|
||||
|
||||
if language != 'en':
|
||||
translation = translate(phrase, language)
|
||||
if not ((input == 'en') and (output == 'en')):
|
||||
translation = translate(phrase, input, output)
|
||||
if translation is not None:
|
||||
translation = translation.decode('utf-8').encode('utf-8')
|
||||
return phenny.reply('"%s" (%s)' % (translation, language))
|
||||
if output == 'en':
|
||||
return phenny.reply('"%s" (%s)' % (translation, input))
|
||||
else: return phenny.reply('"%s" (%s -> %s)' % \
|
||||
(translation, input, output))
|
||||
|
||||
error = "I think it's %s, which I can't translate."
|
||||
return phenny.reply(error % language.title())
|
||||
return phenny.reply(error % input.title())
|
||||
|
||||
# Otherwise, it's English, so mangle it for fun
|
||||
for other in ['de', 'ja']:
|
||||
for other in ['de', 'ja', 'de', 'ja', 'de', 'ja', 'de', 'ja', 'de', 'ja']:
|
||||
phrase = translate(phrase, 'en', other)
|
||||
phrase = translate(phrase, other, 'en')
|
||||
time.sleep(0.1)
|
||||
|
||||
if phrase is not None:
|
||||
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.rule = ('$nick', ur'(?:([a-z]{2}) +)?["“](.+?)["”]\? *$')
|
||||
tr.rule = ('$nick', ur'(?:([a-z]{2}) +)?(?:([a-z]{2}) +)?["“](.+?)["”]\? *$')
|
||||
tr.example = '$nickname: "mon chien"? or $nickname: fr "mon chien"?'
|
||||
tr.priority = 'low'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user