Added optional 'to' handling to translate.

This commit is contained in:
Jeremy Fincher 2004-01-25 18:13:13 +00:00
parent 64b368381f
commit 73a660164d
2 changed files with 5 additions and 1 deletions

View File

@ -68,10 +68,12 @@ class Babelfish(callbacks.Privmsg):
for language in babelfish.available_languages:
_abbrevs[language] = language
def translate(self, irc, msg, args):
"""<from-language> <to-language> <text>
"""<from-language> [to] <to-language> <text>
Returns <text> translated from <from-language> into <to-language>.
"""
if len(args) >= 2 and args[1] == 'to':
args.pop(1)
(fromLang, toLang, text) = privmsgs.getArgs(args, required=3)
try:
fromLang = self._abbrevs[fromLang.lower()]

View File

@ -37,6 +37,8 @@ if network:
def testTranslate(self):
self.assertResponse('translate en sp food',
'alimento')
self.assertResponse('translate en to sp food',
'alimento')
self.assertError('translate foo en food')
self.assertError('translate en foo food')