Created
September 8, 2012 03:16
-
-
Save dingzhihu/3671538 to your computer and use it in GitHub Desktop.
find duplicate strings in android string resources
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
#!/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 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
change the line 17 with
key = res['content']
gives you the same content with different names.