Created
September 3, 2010 00:58
-
-
Save yohfee/563226 to your computer and use it in GitHub Desktop.
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(content, from, to, version = '1.0') | |
query = URI.encode(content) | |
uri = "#{URL}?v=#{version}&q=#{query}&langpair=#{from}%7C#{to}" | |
json = open(uri) | |
JSON.parse(json.string) | |
end | |
end | |
if $0 == __FILE__ | |
puts GoogleLanguage.translate(*ARGV) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment