OLD | NEW |
1 # This Source Code Form is subject to the terms of the Mozilla Public | 1 # This Source Code Form is subject to the terms of the Mozilla Public |
2 # License, v. 2.0. If a copy of the MPL was not distributed with this | 2 # License, v. 2.0. If a copy of the MPL was not distributed with this |
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/. | 3 # file, You can obtain one at http://mozilla.org/MPL/2.0/. |
4 | 4 |
5 import sys | 5 import sys |
6 import os | 6 import os |
7 import re | 7 import re |
8 import json | 8 import json |
9 import struct | 9 import struct |
10 import io | 10 import io |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 key = re.sub(r'\..*', '', parts[-1]) + '_' + re.sub(
r'\W', '_', stringID) | 241 key = re.sub(r'\..*', '', parts[-1]) + '_' + re.sub(
r'\W', '_', stringID) |
242 if key in data: | 242 if key in data: |
243 print 'Warning: locale string %s defined multiple ti
mes' % key | 243 print 'Warning: locale string %s defined multiple ti
mes' % key |
244 | 244 |
245 # Remove access keys | 245 # Remove access keys |
246 value = sourceData[stringID] | 246 value = sourceData[stringID] |
247 match = re.search(r'^(.*?)\s*\(&.\)$', value) | 247 match = re.search(r'^(.*?)\s*\(&.\)$', value) |
248 if match: | 248 if match: |
249 value = match.group(1) | 249 value = match.group(1) |
250 else: | 250 else: |
251 index = value.find("&") | 251 index = value.find('&') |
252 if index >= 0: | 252 if index >= 0: |
253 value = value[0:index] + value[index + 1:] | 253 value = value[0:index] + value[index + 1:] |
254 data[key] = {'message': value} | 254 data[key] = {'message': value} |
255 except Exception, e: | 255 except Exception, e: |
256 print 'Warning: error importing locale data from %s: %s' % (sour
ceFile, e) | 256 print 'Warning: error importing locale data from %s: %s' % (sour
ceFile, e) |
257 | 257 |
258 files[targetFile] = toJson(data) | 258 files[targetFile] = toJson(data) |
259 | 259 |
260 | 260 |
261 def truncate(text, length_limit): | 261 def truncate(text, length_limit): |
262 if len(text) <= length_limit: | 262 if len(text) <= length_limit: |
263 return text | 263 return text |
264 return text[:length_limit - 1].rstrip() + u"\u2026" | 264 return text[:length_limit - 1].rstrip() + u'\u2026' |
265 | 265 |
266 | 266 |
267 def fixTranslationsForCWS(files): | 267 def fixTranslationsForCWS(files): |
268 # Chrome Web Store requires messages used in manifest.json to be present in | 268 # Chrome Web Store requires messages used in manifest.json to be present in |
269 # all languages. It also enforces length limits for extension names and | 269 # all languages. It also enforces length limits for extension names and |
270 # descriptions. | 270 # descriptions. |
271 defaults = {} | 271 defaults = {} |
272 data = json.loads(files['_locales/%s/messages.json' % defaultLocale]) | 272 data = json.loads(files['_locales/%s/messages.json' % defaultLocale]) |
273 for match in re.finditer(r'__MSG_(\S+)__', files['manifest.json']): | 273 for match in re.finditer(r'__MSG_(\S+)__', files['manifest.json']): |
274 name = match.group(1) | 274 name = match.group(1) |
275 defaults[name] = data[name] | 275 defaults[name] = data[name] |
276 | 276 |
277 limits = {} | 277 limits = {} |
278 manifest = json.loads(files['manifest.json']) | 278 manifest = json.loads(files['manifest.json']) |
279 for key, limit in (('name', 45), ('description', 132), ('short_name', 12)): | 279 for key, limit in (('name', 45), ('description', 132), ('short_name', 12)): |
280 match = re.search(r'__MSG_(\S+)__', manifest.get(key, "")) | 280 match = re.search(r'__MSG_(\S+)__', manifest.get(key, '')) |
281 if match: | 281 if match: |
282 limits[match.group(1)] = limit | 282 limits[match.group(1)] = limit |
283 | 283 |
284 for filename in files: | 284 for filename in files: |
285 if not filename.startswith('_locales/') or not filename.endswith('/messa
ges.json'): | 285 if not filename.startswith('_locales/') or not filename.endswith('/messa
ges.json'): |
286 continue | 286 continue |
287 | 287 |
288 data = json.loads(files[filename]) | 288 data = json.loads(files[filename]) |
289 for name, info in defaults.iteritems(): | 289 for name, info in defaults.iteritems(): |
290 data.setdefault(name, info) | 290 data.setdefault(name, info) |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 files['qunit/index.html'] = createScriptPage(params, 'testIndex.html.tmp
l', | 375 files['qunit/index.html'] = createScriptPage(params, 'testIndex.html.tmp
l', |
376 ('general', 'testScripts')) | 376 ('general', 'testScripts')) |
377 | 377 |
378 zipdata = files.zipToString() | 378 zipdata = files.zipToString() |
379 signature = None | 379 signature = None |
380 pubkey = None | 380 pubkey = None |
381 if keyFile != None: | 381 if keyFile != None: |
382 signature = signBinary(zipdata, keyFile) | 382 signature = signBinary(zipdata, keyFile) |
383 pubkey = getPublicKey(keyFile) | 383 pubkey = getPublicKey(keyFile) |
384 writePackage(outFile, pubkey, signature, zipdata) | 384 writePackage(outFile, pubkey, signature, zipdata) |
OLD | NEW |