- if (resp.code == "200")
- lines = Array.new
- resp.body.each_line { |l| lines.push l }
-
- l = lines.join(" ")
- debug "babelfish response: #{l}"
-
- case l
- when /^\s+<td bgcolor=white class=s><div style=padding:10px;>(.*)<\/div><\/td>\s*<\/tr>/m
- answer = $1.gsub(/\s*[\r\n]+\s*/,' ')
- # cache the answer
- if(answer.length > 0)
- @registry["#{trans_pair}/#{data_text}"] = answer
- end
- m.reply answer
- return
- when /^\s+<option value="#{trans_pair}"\s+SELECTED>/
- m.reply "couldn't parse babelfish response html :("
- else
- m.reply "babelfish doesn't support translation from #{trans_from} to #{trans_to}"
+ case body
+ when nil
+ m.reply "couldn't talk to babelfish :("
+ when /^\s*<div id="result"><div style="[^"]*">(.*?)<\/div><\/div>\s*$/
+ answer = $1
+ # cache the answer
+ if(answer.length > 0)
+ @registry["#{trans_pair}/#{data_text}"] = answer