Skip to content

Commit

Permalink
Merge pull request hubotio#111 from OiNutter/master
Browse files Browse the repository at this point in the history
Tidying up translate regular expression.
  • Loading branch information
atmos committed Oct 30, 2011
2 parents 58385b5 + 3849495 commit 94dc791
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/hubot/scripts/translate.coffee
Expand Up @@ -65,10 +65,10 @@ getCode = (language,languages) ->
return code if lang.toLowerCase() is language.toLowerCase()

module.exports = (robot) ->
robot.respond /(translate)( me)?(( from) ([a-z]*))?(( (in)?to) ([a-z]*))? (.*)/i, (msg) ->
term = "\"#{msg.match[10]}\""
origin = if msg.match[5] isnt undefined then getCode(msg.match[5], languages) else 'auto'
target = if msg.match[9] isnt undefined then getCode(msg.match[9], languages) else 'en'
robot.respond /(?:translate)(?: me)?(?:(?: from) ([a-z]*))?(?:(?: (?:in)?to) ([a-z]*))? (.*)/i, (msg) ->
term = "\"#{msg.match[3]}\""
origin = if msg.match[1] isnt undefined then getCode(msg.match[1], languages) else 'auto'
target = if msg.match[2] isnt undefined then getCode(msg.match[2], languages) else 'en'

msg.http("http://translate.google.com/translate_a/t")
.query({
Expand All @@ -90,7 +90,7 @@ module.exports = (robot) ->
language =languages[parsed[2]]
parsed = parsed[0] && parsed[0][0] && parsed[0][0][0]
if parsed
if msg.match[9] is undefined
if msg.match[2] is undefined
msg.send "#{term} is #{language} for #{parsed}"
else
msg.send "The #{language} #{term} translates as #{parsed} in #{languages[target]}"
Expand Down

0 comments on commit 94dc791

Please sign in to comment.