Skip to content

Instantly share code, notes, and snippets.

@massive
Created November 29, 2010 13:51
Show Gist options
  • Select an option

  • Save massive/719970 to your computer and use it in GitHub Desktop.

Select an option

Save massive/719970 to your computer and use it in GitHub Desktop.

Revisions

  1. massive revised this gist Nov 30, 2010. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion locale_diff.rb
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    # Run: curl https://gist.github.com/raw/719970/locale_diff.rb | ruby - en fi
    require 'rubygems'
    require 'yaml'
    require 'pp'

    l1 = ARGV[0]
    l2 = ARGV[1]
  2. massive revised this gist Nov 30, 2010. 1 changed file with 7 additions and 1 deletion.
    8 changes: 7 additions & 1 deletion locale_diff.rb
    Original file line number Diff line number Diff line change
    @@ -12,7 +12,13 @@ def diff(root, compared, structure = [])
    next_root = root[key]
    next_compared = compared.nil? ? nil : compared[key]
    new_structure = structure.dup << key
    puts "#{new_structure.join(".")}" if compared.nil? || compared[key].nil?

    if compared.nil? || compared[key].nil?
    print "#{new_structure.join(".")}"
    print ": \"#{root[key]}\"" if next_root.kind_of? String
    print "\n"
    end

    diff(next_root, next_compared, new_structure) if next_root.kind_of? Hash
    end
    end
  3. massive renamed this gist Nov 29, 2010. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  4. massive created this gist Nov 29, 2010.
    24 changes: 24 additions & 0 deletions Compare two YAML locale files
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    require 'rubygems'
    require 'yaml'
    require 'pp'

    l1 = ARGV[0]
    l2 = ARGV[1]
    first = YAML.load_file(l1 + ".yml")
    second = YAML.load_file(l2 + ".yml")

    def diff(root, compared, structure = [])
    root.each_key do |key|
    next_root = root[key]
    next_compared = compared.nil? ? nil : compared[key]
    new_structure = structure.dup << key
    puts "#{new_structure.join(".")}" if compared.nil? || compared[key].nil?
    diff(next_root, next_compared, new_structure) if next_root.kind_of? Hash
    end
    end

    puts "MISSING FROM #{l2}"
    diff(first[l1], second[l2], [l2])

    puts "\nMISSING FROM #{l1}"
    diff(second[l2], first[l1], [l1])