Skip to content

Instantly share code, notes, and snippets.

@dingzhihu
Created September 8, 2012 03:16
Show Gist options
  • Save dingzhihu/3671538 to your computer and use it in GitHub Desktop.
Save dingzhihu/3671538 to your computer and use it in GitHub Desktop.
find duplicate strings in android string resources
#!/usr/bin/env ruby -w
# find duplicate strings in android string resources
# usage: ruby conflicting_strings strings.xml other_strings.xml
require 'xmlsimple'
def parse_string_resources(file_name)
strings = XmlSimple.xml_in(file_name)['string']
strings
end
def calculate_conflicting_strings(resources)
conflicting_keys = Hash.new(0)
resources.each do |res|
key = res['name']
conflicting_keys[key] += 1
end
conflicting_keys
end
def print_conflicting_keys(conflicting_keys)
conflicting_keys.each do |k, v|
puts "#{k} appears #{v} times" if v > 1
end
end
def main
resources = []
ARGV.each do |file_name|
strings = parse_string_resources(file_name)
strings.each do |string|
resources << string
end
end
conflicting_keys = calculate_conflicting_strings(resources)
print_conflicting_keys(conflicting_keys)
end
main
@oshamahue
Copy link

change the line 17 with key = res['content'] gives you the same content with different names.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment