-
-
Save szabcsee/4270782 to your computer and use it in GitHub Desktop.
get '/translate' do | |
doc = open(params[:url]) { |f| Hpricot (f) } | |
doc.search("//iframe").remove | |
doc.search("//script").remove | |
doc.search("//.headline_meta").remove | |
doc.search("//frameset").remove | |
article = (doc/".post").inner_html | |
google = GoogleFish.new('YOUR-API-KEY') | |
@result = google.translate( params[:language_from], params[:language_to], 'Good night, sleep tight') | |
erb :translated | |
end |
google.translate( params[:language_from], params[:language_to], 'Good night, sleep tight', :format => 'html') that works
The html: true option isn’t directly passed to the Google API, it’s internally converted to format=html - the second example you give here will not pass the format option to the API endpoint. If you could raise an issue (https://github.com/onthebeach/google_fish/issues) I'll take a look when I have some free time
Thanks for the comment. I tried and now it seems to be working.
Only does not work when I pass on the @Article variable in my program, but if I pass in a small text with html tags, it works fine.
I tried to run it from irb and got these errors:
GoogleFish::Request::ApiError: GoogleFish::Request::ApiError
from /Users/szabcsee/.rvm/gems/ruby-1.9.3-p194/gems/google_fish-0.2.2/lib/google_fish.rb:61:in get' from /Users/szabcsee/.rvm/gems/ruby-1.9.3-p194/gems/google_fish-0.2.2/lib/google_fish.rb:34:in
perform_translation'
from /Users/szabcsee/.rvm/gems/ruby-1.9.3-p194/gems/google_fish-0.2.2/lib/google_fish.rb:19:in request_translation' from /Users/szabcsee/.rvm/gems/ruby-1.9.3-p194/gems/google_fish-0.2.2/lib/google_fish.rb:12:in
translate'
from (irb):16
from /Users/szabcsee/.rvm/rubies/ruby-1.9.3-p194/bin/irb:16:in `
1.9.3-p194 :017 >
I Have same error!
I tried to run it from irb and got these errors:
GoogleFish::Request::ApiError: GoogleFish::Request::ApiError
from /Users/szabcsee/.rvm/gems/ruby-1.9.3-p194/gems/google_fish-0.2.2/lib/google_fish.rb:61:in get' from /Users/szabcsee/.rvm/gems/ruby-1.9.3-p194/gems/google_fish-0.2.2/lib/google_fish.rb:34:inperform_translation'
from /Users/szabcsee/.rvm/gems/ruby-1.9.3-p194/gems/google_fish-0.2.2/lib/google_fish.rb:19:in request_translation' from /Users/szabcsee/.rvm/gems/ruby-1.9.3-p194/gems/google_fish-0.2.2/lib/google_fish.rb:12:intranslate'
from (irb):16
from /Users/szabcsee/.rvm/rubies/ruby-1.9.3-p194/bin/irb:16:in `'
1.9.3-p194 :017 >
So that's how I use it and it works. I put the static text instead the article to save on the API consumption while testing. If I use HTML code in the text it gets removed. :html => true does not work, that throws error.
I tried :format => html but nothing happens. I would like the text to be translated with html code being left intact inside.