Skip to content

Instantly share code, notes, and snippets.

@erikaderstedt
Created December 4, 2012 09:03
Show Gist options
  • Save erikaderstedt/4202029 to your computer and use it in GitHub Desktop.
Save erikaderstedt/4202029 to your computer and use it in GitHub Desktop.
Check strings files for stupid errors
#!/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()
@erikaderstedt
Copy link
Author

find $(SRCROOT) -name Localizable.strings -exec Scripts/checkStringsFile.py {} ;

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