Created
April 7, 2011 07:58
-
-
Save joakimk/907260 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
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'httparty' | |
require 'json' | |
# Get one at https://code.google.com/apis/console/b/0 | |
GOOGLE_TRANSLATE_KEY = "" | |
def translate_to_en(text) | |
JSON.parse(HTTParty.get("https://www.googleapis.com/language/translate/v2?key=#{GOOGLE_TRANSLATE_KEY}&q=#{URI.encode(text)}%20d%C3%A5&source=fi&target=en", :format => 'text').to_s)["data"]["translations"][0]["translatedText"] | |
rescue | |
"failed to translate text" | |
end | |
puts translate_to_en(ARGV.join(' ')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment