19a20
> require "json"
32,35c33,34
<         START_MARKUP = "<div id=[\"]?result_box[\"]? dir=[\"]?(ltr|rtl)[\"]?>"
<         END_MARKUP = "</div>"
<         URL = "http://translate.google.com/translate_t" + \
<               "?ie=UTF8&langpair=%s&text=%s"
---
>         URL = "http://translate.google.com/translate_a/t?" + \
>               "client=t&sl=%s&tl=%s&text=%s&ie=utf8"
76c75,76
<             db_escaped, word_escaped = CGI.escape(db), CGI.escape(word)
---
> 			sl, tl = db.split("|")
>             escaped = [sl, tl, word].map{|it| CGI.escape it}
78,96c78,92
<                 Kernel::open(URL % [db_escaped, word_escaped]) do |buffer|
<                     case buffer.read
<                         when /#{START_MARKUP}(.*)/
<                             pos = $2.index(END_MARKUP)
<                             if pos
<                                 res = $2[0..pos-1]
<                                 res = CGI.unescapeHTML(res)
<                                 res = convert_to_utf8(buffer.charset, res)
<                                 defi = Definition.new
<                                 defi.word = word
<                                 defi.database = db
<                                 defi.body = res
<                                 defi.description = available_databases[db]
<                                 [defi]
<                             else
<                                 []
<                             end
<                         else
<                             []
---
>                 Kernel::open(URL % escaped) do |buffer|
>                     json_raw = buffer.read
> 					trans = JSON.parse(json_raw)
> 					if trans and trans['sentences'].length >0
> 	                    res = trans['sentences'][0]['trans']
> 		                res = CGI.unescapeHTML(res)
> 			            res = convert_to_utf8(buffer.charset, res)
> 				        defi = Definition.new
> 					    defi.word = word
>                         defi.database = db
>                         defi.body = res
>                         defi.description = available_databases[db]
>                         [defi]
>                     else
>                         []
