Sha256: d38110a1f9d19df15ed2d4bda12d73f99d63731702ff570ca1755171c76fb3b5

Contents?: true

Size: 619 Bytes

Versions: 9

Compression:

Stored size: 619 Bytes

Contents

namespace :locales do
  desc 'Sort config/locales/*.yml'
  task :sort do
    def deeply_sort_hash(object)
      return object unless object.is_a?(Hash)
      hash = Hash.new
      object.each { |k, v| hash[k] = deeply_sort_hash(v) }
      sorted = hash.sort { |a, b| a[0].to_s <=> b[0].to_s }
      hash.class[sorted]
    end

    Dir[Rails.root.join('config/locales/*.yml')].each do |f|
      STDOUT.print (f).color(:green)
      hash = deeply_sort_hash(YAML.load(File.read(f)))
      File.open(f, 'w') { |file|
        file.write hash.to_yaml
      }
      STDOUT.print ("...done!\n").color(:green)
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
h2ocube_rails_tasks-0.0.14 lib/h2ocube_rails_tasks/tasks/locales.rb
h2ocube_rails_tasks-0.0.13 lib/h2ocube_rails_tasks/tasks/locales.rb
h2ocube_rails_tasks-0.0.12 lib/h2ocube_rails_tasks/tasks/locales.rb
h2ocube_rails_tasks-0.0.11 lib/h2ocube_rails_tasks/tasks/locales.rb
h2ocube_rails_tasks-0.0.10 lib/h2ocube_rails_tasks/tasks/locales.rb
h2ocube_rails_tasks-0.0.9 lib/h2ocube_rails_tasks/tasks/locales.rb
h2ocube_rails_tasks-0.0.8 lib/h2ocube_rails_tasks/tasks/locales.rb
h2ocube_rails_tasks-0.0.7 lib/h2ocube_rails_tasks/tasks/locales.rb
h2ocube_rails_tasks-0.0.6 lib/h2ocube_rails_tasks/tasks/locales.rb