Sha256: b97dea515101ac9eb4d2df8185f6fad68c86efd3c13998cea92e494e20930944

Contents?: true

Size: 1.9 KB

Versions: 1

Compression:

Stored size: 1.9 KB

Contents

require "uri"
require "net/http"

namespace :translation_center do

  def send_exception(exception)
    puts "An error has ocurred while performing this rake, would you like to send the exception to us so we may fix this problem ? press [Y/n]"
    confirm = $stdin.gets.chomp
    
    if confirm.blank? || confirm == 'y' || confirm == 'yes'
      puts 'Sending ...'
      params = {message: "#{exception.message} #{exception.backtrace.join("\n")}"}
      Net::HTTP.post_form(URI.parse('http://translation-center.herokuapp.com/translation_center_feedbacks/create_rake'), params)
      puts 'We have received your feedback. Thanks!'
    end

    # show the exception message
    puts exception.message
    puts exception.backtrace.join("\n")
  end

  desc "Insert yaml translations in db"
  task :yaml2db, [:locale ] => :environment do |t, args|
    begin
      TranslationCenter.yaml2db(args[:locale])
    rescue Exception => e
      send_exception(e)
    end
  end

  desc "Export translations from db to yaml"
  task :db2yaml, [:locale ] => :environment do |t, args|
    begin
      TranslationCenter.db2yaml(args[:locale])
    rescue Exception => e
      send_exception(e)
    end
  end

  desc "Calls yaml2db then db2yaml"
  task :synch, [:locale ] => :environment do |t, args|
    begin
      if TranslationCenter::Category.any?
        puts "WARNING: You already have translations stored in the db, this action will destroy them. Are you sure, you want to continue? press [Y|n]"
        confirm = $stdin.gets.chomp
    
        if confirm.blank? || confirm == 'y' || confirm == 'yes'
          TranslationCenter::Category.destroy_all
        else
          next
        end

      end
      before = Time.now
      TranslationCenter.yaml2db(args[:locale])
      after = Time.now
      p after - before
      TranslationCenter.db2yaml(args[:locale])
      p Time.now - after
    rescue Exception => e
      send_exception(e)
    end  
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
translation_center-1.6.8 lib/tasks/translation_center.rake