浏览 3636 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2006-11-19
ruby版google在线翻译:) My post there 引用 Good work, Thank you! I modified yours, and make it a more flexible utility. If you type translate.rb, it will show you help usage. Also I made it a little rubified, no html any more. Default is from English to Spanish, since my PC does not display Chinese. It can translate from any language to any other language google supported. require 'net/http' def usage "usage: word [lang2 [lang1]]\n" + "Translate word from lang1 (default en, English) to lang2 (default es, Spanish)\n" + "ISO language code: http://www.unicode.org/unicode/onlinedat/languages.html" end def translate arr = ARGV if !arr[0] then puts usage; return end arr[1] = "es" unless arr[1] arr[2] = "en" unless arr[2] langpair = "#{arr[2]}|#{arr[1]}" response = Net::HTTP.post_form(URI.parse("http://translate.google.com/translate_t"), {:text => arr[0], :langpair => langpair}) response.body =~ /<div id=result_box dir=ltr>(.*)<\/div>/ result = $1 result = "No #{langpair} translation available for #{arr[0]}" if result.size == 0 puts result end translate It will be a great utility to help me to learn Spanish, and compare the result from Spanish to French, I see they have the same Latin root!!!! E:\2006_f\ex>translate.rb love amor E:\2006_f\ex>translate.rb love fr amour Thanks again! I think it might be useful for others. Copy it here. If it violates any rule of javaeye, do whatever you ought to do. Thanks! 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2006-11-19
thanks for sharing .. it's awesome
|
|
返回顶楼 | |