lib/googleajax/language.rb in googleajax-1.0.0 vs lib/googleajax/language.rb in googleajax-1.0.1

- old
+ new

@@ -12,12 +12,20 @@ # Translates the supplied text, matching the destination language. # source and destination can be the language code ("en") or a symbol (:english). # source can also be an empty string, in which case Google does an auto-detection and # will set :detected_source_language to the language it used as a source. + # + # Google limits GET request to 2000 chars, but allows POST for the translate request + # so we use this to allow texts up to 5000 chars (another limit imposed by Google). + # + # TODO: Give easy way to shorten text downto the acceptable limit. def self.translate(query, source, destination, args = {}) - langpair = [source, destination].map{|l| LANGUAGE_CODE[l] || l.to_s}.join("%7C") - args = { :langpair => langpair }.merge(args) + langpair = [source, destination].map{|l| LANGUAGE_CODE[l] || l.to_s}.join("|") + args = { + :langpair => langpair, + :http_method => :post + }.merge(args) get(:translate, query, args) end LANGUAGE_CODE = { \ No newline at end of file