Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: packagerChrome.py

Issue 5702288324689920: Make sure that translations used in manifest.json exist in all languages (Closed)
Patch Set: Addressed comment Created March 13, 2014, 3:44 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: packagerChrome.py
===================================================================
--- a/packagerChrome.py
+++ b/packagerChrome.py
@@ -160,6 +160,12 @@
sourceFiles = map(lambda f: os.path.abspath(os.path.join(baseDir, f)), sourceFiles)
files[file] = doRewrite(sourceFiles, args)
+def toJson(data):
+ return json.dumps(
+ data, ensure_ascii=False, sort_keys=True,
+ indent=2, separators=(',', ': ')
+ ).encode('utf-8') + '\n'
+
def importGeckoLocales(params, files):
import localeTools
@@ -261,8 +267,7 @@
except Exception, e:
print 'Warning: error importing locale data from %s: %s' % (sourceFile, e)
- files[targetFile] = json.dumps(data, ensure_ascii=False, sort_keys=True,
- indent=2, separators=(',', ': ')).encode('utf-8') + '\n'
+ files[targetFile] = toJson(data)
if params['type'] == 'opera':
# Opera has a slightly different locale mapping
@@ -279,6 +284,24 @@
files[operaFile] = files[chromeFile]
del files[chromeFile]
+def fixMissingTranslations(files):
+ # Chrome requires messages used in manifest.json to be given in all languages
+ defaults = {}
+ data = json.loads(files['_locales/%s/messages.json' % defaultLocale])
+ for match in re.finditer('__MSG_(\S+)__', files['manifest.json']):
+ name = match.group(1)
+ defaults[name] = data[name]
+
+ for filename in files:
+ if not filename.startswith('_locales/') or not filename.endswith('/messages.json'):
+ continue
+
+ data = json.loads(files[filename])
+ for name, info in defaults.iteritems():
+ data.setdefault(name, info)
+
+ files[filename] = toJson(data)
+
def signBinary(zipdata, keyFile):
import M2Crypto
if not os.path.exists(keyFile):
@@ -343,6 +366,8 @@
if metadata.has_section('import_locales'):
importGeckoLocales(params, files)
+ fixMissingTranslations(files)
+
if devenv:
files['devenvPoller__.js'] = createPoller(params)
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld