Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def deeply_sort_hash(object)
- return object.sort if object.is_a?(Array)
- return object unless object.is_a?(Hash)
- hash = RUBY_VERSION >= '1.9' ? Hash.new : ActiveSupport::OrderedHash.new
- object.each { |k, v| hash[k] = deeply_sort_hash(v) }
- sorted = hash.sort_by { |(k, v)| [v.is_a?(String) ? 0 : 1, k.to_s.downcase] }
- hash.class[sorted]
- end
- ['de', 'en'].each do |locale|
- files = Dir[Rails.root.join('config', 'locales', "*#{locale}.yml").to_s].sort; nil
- translations = {}; nil
- files.each { |file| translations.deep_merge!(YAML.load_file(file)) }; nil
- output = Rails.root.join('config', 'locales', "#{locale}.yml").to_s
- sorted = deeply_sort_hash(DeepHashTransformer.new(translations).stringify); nil
- File.open(output, 'w') { |file| file.write(sorted.to_yaml) }
- end
Add Comment
Please, Sign In to add comment