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: for language in babelfish.available_languages:
_abbrevs[language] = language _abbrevs[language] = language
def translate(self, irc, msg, args): 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>. 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) (fromLang, toLang, text) = privmsgs.getArgs(args, required=3)
try: try:
fromLang = self._abbrevs[fromLang.lower()] fromLang = self._abbrevs[fromLang.lower()]

View File

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