Created
January 21, 2011 02:06
-
-
Save yohfee/789126 to your computer and use it in GitHub Desktop.
google_language.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
require 'open-uri' | |
require 'json' | |
module GoogleLanguage | |
extend self | |
URL = "http://ajax.googleapis.com/ajax/services/language/translate" | |
def translate(file) | |
IO.foreach(file) do |line| | |
query = URI.encode(line) | |
uri = "#{URL}?v=1.0&q=#{query}&langpair=en%7Cja" | |
json = open(uri) | |
data = JSON.parse(json.string) | |
puts data['responseData']['translatedText'] | |
end | |
end | |
end | |
if $0 == __FILE__ | |
puts GoogleLanguage.translate(ARGV[0]) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment