snej / Murky

A GUI client app for the Mercurial version-control system. Written for Mac OS X, in Objective-C.

Clone this repository (size: 6.0 MB): HTTPS / SSH
$ hg clone http://bitbucket.org/snej/murky/
commit 139: 582ab9dabe77
parent 138: bf51f845a755
branch: default
refining the logic for when nibs and strings need to be updated
David Keegan / keegan3d
3 months ago

Changed (Δ281 bytes):

raw changeset »

Localize.py (28 lines added, 17 lines removed)

Up to file-list Localize.py:

@@ -110,12 +110,18 @@ def md5(file):
110
110
    md5Sum = runCommand('/usr/bin/openssl md5', file)
111
111
    return md5Sum.split('=')[1].strip()
112
112
    
113
def langProjName(language):
114
    return language.strip()+'.lproj'
115
    
116
def nibToStringFileName(nibFile):
117
    return nibFile.rstrip('.xib')+'.strings'
118
    
113
119
def generateStringsFile(nibFile, utf8=False):
114
120
    '''
115
121
    Generate a .strings file from a nib
116
122
    If utf8 is True the .strings files will be re-encoded as utf-8
117
123
    '''
118
    nibFileStrings = nibFile.rstrip('.xib')+'.strings'
124
    nibFileStrings = nibToStringFileName(nibFile)
119
125
    runCommand('ibtool', '--generate-strings-file %s %s' % (nibFileStrings, nibFile))
120
126
    
121
127
    if utf8:
@@ -125,7 +131,7 @@ def generateStringsFile(nibFile, utf8=Fa
125
131
    
126
132
def writeNib(fromFile, toFile, utf8=False):
127
133
    '''convert one localized nib from one language to another'''
128
    toStrings = toFile.rstrip('.xib')+'.strings'
134
    toStrings = nibToStringFileName(toFile)
129
135
    runCommand('ibtool', '--strings-file %s --write %s %s' % (toStrings, toFile, fromFile))
130
136
    
131
137
    if utf8:
@@ -135,7 +141,7 @@ def writeNib(fromFile, toFile, utf8=Fals
135
141
 
136
142
def genStrings(toLangs, globString, utf8=False):
137
143
    for eachToLang in toLangs:
138
        toLangLproj = eachToLang.strip()+'.lproj'
144
        toLangLproj = langProjName(eachToLang)
139
145
        runCommand('genstrings', '-o %s %s' % (toLangLproj, globString))
140
146
        localizableStrings = os.path.join(toLangLproj, 'Localizable.strings')
141
147
        if utf8:
@@ -155,23 +161,28 @@ def localizeNibs(fromLang, toLangs, nibs
155
161
    else:
156
162
        jsonData = {}
157
163
        
158
    fromLangLproj = fromLang.strip()+'.lproj'
159
    for eachToLang in toLangs:
160
        toLangLproj = eachToLang.strip()+'.lproj'
161
        for eachNib in nibs:
162
            eachNib = eachNib.strip()
163
            if not(eachNib.endswith('.xib')):
164
                eachNib += '.xib'
165
            fromNib = os.path.join(fromLangLproj, eachNib)
164
    fromLangLproj = langProjName(fromLang)
165
    for eachNib in nibs:
166
        eachNib = eachNib.strip()
167
        if not(eachNib.endswith('.xib')):
168
            eachNib += '.xib'
169
        fromNib = os.path.join(fromLangLproj, eachNib)
170
        
171
        #get md5 and update the json data
172
        fromNibMd5 = md5(fromNib)
173
        #check if the strings for the fromNib need to the updated
174
        if not(os.path.isfile(nibToStringFileName(fromNib))) or not(fromNib in jsonData) or jsonData[fromNib] != fromNibMd5:
175
            generateStringsFile(fromNib, utf8)
176
        
177
        #write the localized nibs
178
        for eachToLang in toLangs:
179
            toLangLproj = langProjName(eachToLang)
166
180
            toNib =  os.path.join(toLangLproj, eachNib)
167
            fromNibMd5 = md5(fromNib)
168
            
169
            #if the 'to nib' does not exist, or the 'from nib' is not in the json data, or the checksum does not match
170
181
            if not(os.path.isfile(toNib)) or not(fromNib in jsonData) or jsonData[fromNib] != fromNibMd5:
171
                generateStringsFile(fromNib, utf8)
172
182
                writeNib(fromNib, toNib, utf8)
173
                jsonData[fromNib] = fromNibMd5
174
            
183
                
184
        jsonData[fromNib] = fromNibMd5
185
                
175
186
    #update Localize.json
176
187
    localizeData = open(localizeJson, 'w')
177
188
    json.dump(jsonData, localizeData, indent=4)