See original post by killme2008 from the following link
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.
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!!!! :)
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!
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!
- 04:59
- 浏览 (1726)
- 论坛浏览 (1882)
- 评论 (1)
- 相关推荐
发表评论
该博客是同时发布到论坛的,无法评论在论坛已被锁定的帖子







评论排行榜