Skip to content

Commit

Permalink
Updated the Google Translate task to handle timeout errors. Also ensu…
Browse files Browse the repository at this point in the history
…red all objects passed to Google are strings.
  • Loading branch information
Richard Johansson committed Mar 17, 2009
1 parent 6957c62 commit 14b3fac
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions tasks/translate.rake
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,25 @@ namespace :translate do
include HTTParty
base_uri 'ajax.googleapis.com'
def self.translate(string, to, from)
get("/ajax/services/language/translate",
:query => {:langpair => "#{from}|#{to}", :q => string, :v => 1.0},
:format => :json)
tries = 0
begin
get("/ajax/services/language/translate",
:query => {:langpair => "#{from}|#{to}", :q => string, :v => 1.0},
:format => :json)
rescue
tries += 1
puts("SLEEPING - retrying in 5...")
sleep(5)
retry if tries < 10
end
end
end

I18n.backend.send(:init_translations)

translations = {}
Translate::Keys.new.i18n_keys(ENV['FROM']).each do |key|
from_text = I18n.backend.send(:lookup, ENV['FROM'], key)
from_text = I18n.backend.send(:lookup, ENV['FROM'], key).to_s
to_text = I18n.backend.send(:lookup, ENV['TO'], key)
if !from_text.blank? && to_text.blank?
print "#{key}: '#{from_text[0, 40]}' => "
Expand Down

0 comments on commit 14b3fac

Please sign in to comment.