Sha256: cb38dd4595a778d3fb6728889aa9e34b4c2f0a51145c7e64afe473fb89933a57

Contents?: true

Size: 1.75 KB

Versions: 1

Compression:

Stored size: 1.75 KB

Contents

require File.join(File.dirname(__FILE__), '..', 'web_translate_it')

namespace :trans do  
  desc "Fetch translation files from Web Translate It"
  task :fetch, :locale do |task, args|
    welcome_message
    puts "Fetching file for locale #{args.locale}…"
    configuration = WebTranslateIt::Configuration.new
    configuration.files.each do |file|
      response_code = file.fetch(args.locale)
      handle_response(file.file_path_for_locale(args.locale), response_code)
    end
  end
  
  namespace :fetch do
    desc "Fetch all the translation files from Web Translate It"
    task :all do
      welcome_message
      configuration = WebTranslateIt::Configuration.new
      locales = configuration.locales
      configuration.ignore_locales.each do |ignore|
        locales.delete(ignore)
      end
      puts "Fetching all files for all locales…"
      locales.each do |locale|
        configuration.files.each do |file|
          response_code = file.fetch(locale) 
          handle_response(file.file_path_for_locale(locale), response_code)
        end
      end
    end
  end
  
  desc "Upload a translation file to Web Translate It"
  task :upload, :locale do |task, args|
    welcome_message
    puts "Uploading file for locale #{args.locale}…"
    configuration = WebTranslateIt::Configuration.new
    configuration.files.each do |file|
      response_code = file.upload(args.locale)
      handle_response(file.file_path_for_locale(args.locale), response_code)
    end
  end
    
  def handle_response(file_path, response_code)
    if response_code < 400
      puts "#{file_path}: #{response_code}, OK"
    else
      puts "#{file_path}: #{response_code}, Problem!"
    end
  end
  
  def welcome_message
    puts "Web Translate It v#{WebTranslateIt::Util.version}"
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
web_translate_it-1.4.4 lib/web_translate_it/tasks.rb