lib/meme-translator/translator.rb
# Change this to the languages you want this to randomly choose from
Change this to the languages you want this to randomly choose from
Change this to the languages you want this to randomly choose from
def translate_phrase(phrase, to, from)
    tries = 1
    loop do
      begin
          puts "Translating phrase '#{phrase}' into #{@@languages[to]}."
          return JSON.parse(@api.translate(phrase.gsub("\"", "\\\""), to, from: from)).first['translations'].first['text'].gsub("\\\"", "\""), nil
      rescue Exception => e
        puts e
        if tries == 5
          puts "Program cannot recover. Saving progress and exiting."
          return phrase, :abort
        else
          puts "Something went wrong on attempt #{tries}/5. Trying again in 10 seconds"
          tries += 1
          sleep 10
        end
      end
    end
  end
def translate_phrase ( phrase , to , from ) tries = 1 loop do begin puts "Translating phrase '#{phrase}' into #{@@languages[to]}." return JSON . parse ( @api . translate ( phrase . gsub ( "\"" , "\\\"" ) , to , from : from ) ) . first [ 'translations' ] . first [ 'text' ] . gsub ( "\\\"" , "\"" ) , nil rescue Exception => e puts e if tries == 5 puts "Program cannot recover. Saving progress and exiting." return phrase , :abort else puts "Something went wrong on attempt #{tries}/5. Trying again in 10 seconds" tries += 1 sleep 10 end end end end
Change this to the languages you want this to randomly choose from
Change this to the languages you want this to randomly choose from
phrase
<not_specific>
to
<not_specific>
from
<not_specific>