Skip to content

Instantly share code, notes, and snippets.

@yohfee
Created September 3, 2010 00:58
Show Gist options
  • Save yohfee/563226 to your computer and use it in GitHub Desktop.
Save yohfee/563226 to your computer and use it in GitHub Desktop.
# 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