-
-
Save ifcwebserver/7726555 to your computer and use it in GitHub Desktop.
This script helps to compare and merge an old version of YAML local file of your target language against an up-to-date master language file
This file contains hidden or 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
# This script helps to compare and merge an old version of YAML local file of your target language against an up-to-date master language file, which contains new strings | |
# It still need some improvments so please do not forget to validate the YAML by pasteing it into http://yamllint.com/ | |
# Run: curl https://gist.github.com/raw/7726555/locale_diff.rb | ruby - client.en.yml client.ar.yml > new_client.ar.yml | |
require 'rubygems' | |
require 'yaml' | |
require 'pp' | |
master_local = ARGV[0] | |
my_local = ARGV[1] | |
master = YAML.load_file(master_local ) | |
local = YAML.load_file(my_local ) | |
def diff(root, compared, structure = []) | |
$level += 1 | |
root.each do |key,value| | |
if value.class != String | |
print " "*($level-1) | |
print key + ":" + "\n" | |
end | |
next_root = root[key] | |
next_compared = compared.nil? ? nil : compared[key] | |
new_structure = structure.dup << key | |
if compared.nil? || compared[key].nil? | |
if value.class == String | |
print " "*($level-1) | |
print key | |
string_quote = value.include?("\"") ? "'" : "\"" | |
print ": " + string_quote + value + string_quote + "\n" | |
end | |
else | |
if next_compared.class == String | |
print " "*($level-1) | |
print key | |
string_quote = next_compared.include?("\"") ? "'" : "\"" | |
print ": " + string_quote + next_compared + string_quote + "\n" | |
end | |
end | |
diff(next_root, next_compared, new_structure) if next_root.kind_of? Hash | |
end | |
$level -= 1 | |
# print "\n" # uncomment if you wish to have an empty line when the indentation level changes | |
end | |
$level=0 | |
diff(master, local, [my_local]) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run:
curl https://gist.github.com/raw/7726555/locale_diff.rb | ruby - client.en.yml client.ar.yml > new_client.ar.yml