Created
March 13, 2015 15:12
-
-
Save bajalovic/75fac374ef57a1cbbe25 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
require 'yaml' | |
def main | |
lang_file_1 = ARGV[0] | |
lang_file_2 = ARGV[1] | |
lang_1 = YAML::load(File.open lang_file_1) | |
lang_2 = YAML::load(File.open lang_file_2) | |
lang_1_key = lang_1.keys.first | |
lang_2_key = lang_2.keys.first | |
@keys = {} | |
all_keys lang_1[lang_1_key] | |
lang_1_keys = @keys | |
@keys = {} | |
all_keys lang_2[lang_2_key] | |
lang_2_keys = @keys | |
a_not_in_b = lang_1_keys.keys - lang_2_keys.keys | |
b_not_in_a = lang_2_keys.keys - lang_1_keys.keys | |
if a_not_in_b.empty? && b_not_in_a.empty? | |
puts "============================" | |
puts "Both files contain same keys" | |
puts "============================" | |
else | |
puts "========================================================" | |
puts "Keys exist in the first file, but not in the second one" | |
puts "========================================================" | |
a_not_in_b.each do |key| | |
puts "#{key}: #{lang_1_keys[key]}" | |
end | |
puts "\n\n" | |
puts "========================================================" | |
puts "Keys exist in the second file, but not in the first one" | |
puts "========================================================" | |
b_not_in_a.each do |key| | |
puts "#{key}: #{lang_2_keys[key]}" | |
end | |
end | |
end | |
def all_keys hash, parent = "" | |
hash.each do |key, value| | |
if value.is_a? Hash | |
@keys.merge all_keys(value, [parent, key].select{|i| i unless i == ""}.join(".")) | |
else | |
@keys[[parent, key].select{|i| i unless i == ""}.join(".")] = value | |
end | |
end | |
end | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Second version of https://gist.github.com/bajalovic/b9936be1463f3cdb2e1b
In this version, output is
translation_key: value