Created
December 4, 2012 09:03
-
-
Save erikaderstedt/4202029 to your computer and use it in GitHub Desktop.
Check strings files for stupid errors
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 python | |
import sys, codecs, re, os.path | |
comment = re.compile('/\*.*\*/',re.DOTALL) | |
regular = re.compile('^\s*"([^"]*)"\s*=\s*"([^"]*)"\s*;\s*$') | |
if len(sys.argv) < 2: | |
print "Usage: checkStringsFile.py <filename>" | |
sys.exit(1) | |
inputFileName = sys.argv[1] | |
if os.path.basename(inputFileName) == 'InfoPlist.strings': | |
sys.exit(2) | |
f = codecs.open(inputFileName, mode='r', encoding='utf-16',errors='ignore') | |
try: | |
entireFile = f.read() | |
except UnicodeError: | |
print "%s:error: Invalid encoding" % (inputFileName) | |
entireFile = "" | |
f.close() | |
entireFile = comment.sub("",entireFile); | |
entireFile = entireFile.split("\n") | |
# Allow empty lines and lines that match 'regular'. | |
number = 0 | |
for line in entireFile: | |
number = number+1 | |
if len(line.strip()) == 0: | |
continue | |
if regular.match(line): | |
continue | |
print "%s:%s:error:" % (inputFileName, number), line.strip() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
find $(SRCROOT) -name Localizable.strings -exec Scripts/checkStringsFile.py {} ;