Skip to content

Instantly share code, notes, and snippets.

@leejarvis
Created May 25, 2010 11:42
Show Gist options
  • Save leejarvis/413044 to your computer and use it in GitHub Desktop.
Save leejarvis/413044 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'open-uri'
require 'json'
# Google translate
def translate(text, langto='en', langfrom='en')
text.gsub!(/\s+/, '+')
s = open("http://translate.google.com/translate_a/t?client=t&text=#{text}&hl=#{langfrom}&tl=#{langto}")
puts "Text translation: " + JSON.parse(s.read)['sentences'].first['trans']
end
translate("hello there", "de")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment