Skip to content

Instantly share code, notes, and snippets.

@dbarden
Created June 4, 2020 15:05
Show Gist options
  • Save dbarden/f9d0d1c3f4a6b66c1f64aeb048529b56 to your computer and use it in GitHub Desktop.
Save dbarden/f9d0d1c3f4a6b66c1f64aeb048529b56 to your computer and use it in GitHub Desktop.
Small ruby script that reads all the keys in Localizable.strings and make sure that all have the same keys
#!/usr/bin/env ruby
require 'set'
files = `find . -name Localizable.strings`.split("\n")
# Builds a list of keys
keys = Set.new
MATCH_FORMAT = /\"(.*)\"[ ]*=[ ]*\".*\"/
files.each do | file |
File.open(file).each do | line |
line.match(MATCH_FORMAT) {|m|
keys.add(m.captures.first)
}
end
end
# Checks that all the files contains all keys
files.each do |file|
file_data = File.open(file).read
keys.each do | key |
match = file_data.match(/\"#{key}\"/)
if match.nil?
STDERR.puts "#{File.absolute_path(file)}:1:1: warning: Missing #{key}\n"
end
end
end %
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment