Skip to content

Instantly share code, notes, and snippets.

@tobiashm
Created December 12, 2012 16:32
Show Gist options
  • Save tobiashm/4269294 to your computer and use it in GitHub Desktop.
Save tobiashm/4269294 to your computer and use it in GitHub Desktop.
Rake task to compare Spree locale file with 'baseline'
desc "compare spree en.yml with i18n da.yml"
task :compare do
require 'open-uri'
core = %w[api core dash promo].inject({}) do |memo, name|
memo.deep_merge YAML.load(open "https://raw.github.com/spree/spree/#{ENV['branch'] || 'master'}/#{name}/config/locales/en.yml")
end
other = YAML.load_file File.expand_path('../../../config/locales/da.yml', __FILE__)
en, da = core['en'], other['da']
puts ["=" * 60, "* checking en against da", "=" * 60].join("\n")
compare_yaml_hash en, da
puts ["=" * 60, "* checking da against en", "=" * 60].join("\n")
compare_yaml_hash da, en
end
def compare_yaml_hash(hash1, hash2, context = [])
hash1.each do |key, value|
unless hash2.key?(key)
puts "Missing key : #{key} in path `#{context.join(".")}` (#{value})"
next
end
if value.is_a?(Hash)
if hash2[key]
compare_yaml_hash(value, hash2[key], (context + [key]))
else
puts "Missing context for path `#{context.join(".")}.#{key}`"
end
next
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment