Skip to content

Instantly share code, notes, and snippets.

@seb
Created January 5, 2011 16:45
Show Gist options
  • Save seb/766571 to your computer and use it in GitHub Desktop.
Save seb/766571 to your computer and use it in GitHub Desktop.
def seethreepio(text, from = 'fr', to = 'en')
escaped_text = CGI::escape(text)
host = Net::HTTP.new("www.googleapis.com",443)
host.use_ssl = true
body = JSON.parse(
host.get("/language/translate/v2?key=YOUR_KEY_GOES_HERE&source=#{from}&target=#{to}&q=#{escaped_text}").body)
body['data']['translations'].first['translatedText']
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment