-
-
Save alexiamcdonald/7af18dceba103f4f46ce6a9768ab70de to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
LOCALE_1 = "~/Code/project/config/locales/fi.yml" | |
LOCALE_2 = "~/Code/project/config/locales/en.yml" | |
require 'yaml' | |
def flatten_keys(hash, prefix="") | |
keys = [] | |
hash.keys.each do |key| | |
if hash[key].is_a? Hash | |
current_prefix = prefix + "#{key}." | |
keys << flatten_keys(hash[key], current_prefix) | |
else | |
keys << "#{prefix}#{key}" | |
end | |
end | |
prefix == "" ? keys.flatten : keys | |
end | |
def compare(locale_1, locale_2) | |
yaml_1 = YAML.load(File.open(File.expand_path(locale_1))) | |
yaml_2 = YAML.load(File.open(File.expand_path(locale_2))) | |
keys_1 = flatten_keys(yaml_1[yaml_1.keys.first]) | |
keys_2 = flatten_keys(yaml_2[yaml_2.keys.first]) | |
missing = keys_2 - keys_1 | |
file = locale_1.split('/').last | |
if missing.any? | |
puts "Missing from #{file}:" | |
missing.each { |key| puts " - #{key}" } | |
else | |
puts "Nothing missing from #{file}." | |
end | |
end | |
compare(LOCALE_1, LOCALE_2) | |
puts | |
compare(LOCALE_2, LOCALE_1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment