Created
May 15, 2010 09:09
-
-
Save eduardo/402106 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# example of translator snippet | |
require "translator" | |
puts Translator.translate("Hello World", "en", "fr") |
This file contains hidden or 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
# Ruby Implementation of Google Translate | |
# | |
# requires the httparty gem. | |
# | |
# Copyright Bryce Roney <[email protected]> 2008 | |
# http://bryce.insanesparrow.com | |
require "rubygems" | |
gem "httparty" | |
require "httparty" | |
class Translator | |
include HTTParty | |
base_uri "http://ajax.googleapis.com/ajax/services/language" | |
def self.translate(text, from, to) | |
options = {:query => {:v => "1.0", :q => text, :langpair => "#{from}|#{to}"}} | |
format :json | |
response = get("/translate", options) | |
return response["responseData"]["translatedText"] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment