Commits

David Keegan  committed 6711775

Localize.py command line script that uses md5 checksum to determin of a localized nib should be created. The md5 of the 'fromFile' is stored in Localize.json.

build timing:
real 0m5.157s
user 0m4.830s
sys 0m0.608s

with md5 check:
real 0m2.682s
user 0m2.520s
sys 0m0.510s

  • Participants
  • Parent commits 6c94af8

Comments (0)

Files changed (3)

File Localize.json

+{
+    "German.lproj/Projects.xib": "3d7c108b95ff7436ecfa6bcb6932edb9", 
+    "German.lproj/MainMenu.xib": "012d51d8ee26799d88614c77de7613ae", 
+    "French.lproj/Repo.xib": "bb20d4c8074da7465e354543815e83d4", 
+    "French.lproj/MainMenu.xib": "012d51d8ee26799d88614c77de7613ae", 
+    "German.lproj/Repo.xib": "bb20d4c8074da7465e354543815e83d4", 
+    "French.lproj/Projects.xib": "3d7c108b95ff7436ecfa6bcb6932edb9"
+}
+#!/usr/bin/python
+
+import os, sys
+import subprocess
+from optparse import OptionParser
+try:
+    #python2.6+
+    import json
+except ImportError:
+    #python2.5
+    import simplejson as json
+
+def runCommand(command, args):
+    '''run shell commands'''
+    commandAndArgs = '%s %s' % (command, args)
+    proc = subprocess.Popen(commandAndArgs, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+    stdout, stderr = proc.communicate()
+    if stderr != '':
+        raise TestPyError(commandAndArgs, stderr)
+    return stdout
+ 
+def md5(file):
+    '''get the md5 checksum of a file'''
+    md5Sum = runCommand('/usr/bin/openssl md5', file)
+    return md5Sum.split('=')[1].strip()
+    
+def translateNib(fromFile, toFile):
+    '''create a nib from another nib and strings file'''
+    print 'Localizing', toFile
+    #get the md5 of the fromFile to see if it has been updated
+    localizeJson = os.path.abspath('Localize.json')
+    if os.path.isfile(localizeJson):
+        localizeData = open(localizeJson, 'r')
+        jsonData = json.load(localizeData)
+        localizeData.close()
+    else:
+        jsonData = {}
+    
+    #if the fromFile is not in the jsonData or the md5 is different 
+    #generate a new nib and update the jsonData
+    fromFileMd5 = md5(fromFile)
+    if not(toFile in jsonData) or jsonData[toFile] != fromFileMd5:
+        #generate nib
+        toStrings = toFile.rstrip('.xib')+'.strings'
+        runCommand('ibtool', '--strings-file %s --write %s %s' % (toStrings, toFile, fromFile))
+        print '    ', toFile, 'updated'
+        
+        #update Localize.json
+        jsonData[toFile] = fromFileMd5
+        localizeData = open(localizeJson, 'w')
+        json.dump(jsonData, localizeData, indent=4)
+        localizeData.close()
+    
+if __name__ == '__main__':
+    '''Command line options'''
+    
+    opts = OptionParser()
+    opts.add_option('--write', '-w', dest='write', help='write to this nib file', metavar='NIB')
+    options, arguments = opts.parse_args()
+    
+    if len(arguments) == 0:
+        sys.stderr.write('no filepath provided')
+    
+    else:
+        translateNib(arguments[0], options.write)

File Murky.xcodeproj/project.pbxproj

 			);
 			runOnlyForDeploymentPostprocessing = 0;
 			shellPath = /bin/sh;
-			shellScript = "# Extract English strings (use this to check if you added new strings to your nibs)\nibtool --generate-strings-file English.lproj/MainMenu.strings English.lproj/MainMenu.xib\nibtool --generate-strings-file English.lproj/Projects.strings English.lproj/Projects.xib\nibtool --generate-strings-file English.lproj/Repo.strings English.lproj/Repo.xib\n\n# Generate French interface\nibtool --strings-file French.lproj/MainMenu.strings --write French.lproj/MainMenu.xib English.lproj/MainMenu.xib\nibtool --strings-file French.lproj/Projects.strings --write French.lproj/Projects.xib English.lproj/Projects.xib\nibtool --strings-file French.lproj/Repo.strings --write French.lproj/Repo.xib English.lproj/Repo.xib\n\n# Generate German interface\nibtool --strings-file German.lproj/MainMenu.strings --write German.lproj/MainMenu.xib English.lproj/MainMenu.xib\nibtool --strings-file German.lproj/Projects.strings --write German.lproj/Projects.xib English.lproj/Projects.xib\nibtool --strings-file German.lproj/Repo.strings --write German.lproj/Repo.xib English.lproj/Repo.xib\n";
+			shellScript = "# Extract English strings (use this to check if you added new strings to your nibs)\nibtool --generate-strings-file English.lproj/MainMenu.strings English.lproj/MainMenu.xib\nibtool --generate-strings-file English.lproj/Projects.strings English.lproj/Projects.xib\nibtool --generate-strings-file English.lproj/Repo.strings English.lproj/Repo.xib\n\n# Generate French interface\n${SRCROOT}/Localize.py --write French.lproj/MainMenu.xib English.lproj/MainMenu.xib\n${SRCROOT}/Localize.py --write French.lproj/Projects.xib English.lproj/Projects.xib\n${SRCROOT}/Localize.py --write French.lproj/Repo.xib English.lproj/Repo.xib\n\n# Generate German interface\n${SRCROOT}/Localize.py --write German.lproj/MainMenu.xib English.lproj/MainMenu.xib\n${SRCROOT}/Localize.py --write German.lproj/Projects.xib English.lproj/Projects.xib\n${SRCROOT}/Localize.py --write German.lproj/Repo.xib English.lproj/Repo.xib\n";
 		};
 /* End PBXShellScriptBuildPhase section */