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

Unified Diff: packagerChrome.py

Issue 29517660: Issue 5477 - Import everything from imported locales (Closed)
Patch Set: Further simplifying Created Aug. 18, 2017, 2:34 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 | packagerEdge.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: packagerChrome.py
diff --git a/packagerChrome.py b/packagerChrome.py
index 3e1a452a1a5b79fa7ff7316930ac911aab8162a6..96ca25b9d6fcbd288c5b58adefd0a87b2d1d3e21 100644
--- a/packagerChrome.py
+++ b/packagerChrome.py
@@ -190,7 +190,35 @@ def toJson(data):
).encode('utf-8') + '\n'
-def importGeckoLocales(params, files):
+def set_translation_and_additional_info(data, key, source, stringID):
+ """Sets data[key] to the desired {'message':value}, adds all additional
+ info from the source dict"""
Sebastian Noack 2017/08/18 14:53:59 As per PEP-257, the trailing """ goes onto a new l
tlucas 2017/08/18 15:10:35 Done.
+ value = source[stringID]['message']
Sebastian Noack 2017/08/18 14:53:59 It seems all usage of "source" and "stringID" here
tlucas 2017/08/18 15:10:34 Done.
+
+ data[key] = {'messages': value}
+ for k, v in source[stringID].items():
+ data[key].setdefault(k, v)
+
+
+def set_translation_without_access_keys(data, key, source, stringID):
Sebastian Noack 2017/08/18 14:53:59 I think better names for these functions would be
tlucas 2017/08/18 15:10:35 Done.
+ """only set {'message': value} in data-dictionary, after stripping
+ undesired gecko-style access keys"""
+ value = source[stringID]
+
+ # Remove access keys from possible gecko-style
+ # translations
+ match = re.search(r'^(.*?)\s*\(&.\)$', value)
+ if match:
+ value = match.group(1)
+ else:
+ index = value.find('&')
+ if index >= 0:
+ value = value[0:index] + value[index + 1:]
+
+ data[key] = {'message': value}
+
+
+def import_locales(params, files):
import localeTools
# FIXME: localeTools doesn't use real Chrome locales, it uses dash as
@@ -227,12 +255,19 @@ def importGeckoLocales(params, files):
data = json.loads(files[targetFile].decode('utf-8'))
try:
+ # .json and other formats provide translations differently and
Sebastian Noack 2017/08/18 14:53:59 The other format is the Gecko format. "The WebE
tlucas 2017/08/18 15:10:35 Done.
+ # / or provide additional information like e.g. "placeholders".
Sebastian Noack 2017/08/18 14:53:59 It is supposed to be "and/or" without space.
tlucas 2017/08/18 15:10:34 Done.
+ # We want to adhere to that / preserve the addtional info
if sourceFile.endswith('.json'):
with io.open(sourceFile, 'r', encoding='utf-8') as handle:
- sourceData = {k: v['message'] for k, v in json.load(handle).iteritems()}
+ sourceData = json.load(handle)
+
+ set_translation = set_translation_and_additional_info
else:
sourceData = localeTools.readFile(sourceFile)
+ set_translation = set_translation_without_access_keys
+
# Resolve wildcard imports
if keys == '*' or keys == '=*':
importList = sourceData.keys()
@@ -255,16 +290,7 @@ def importGeckoLocales(params, files):
if key in data:
print 'Warning: locale string %s defined multiple times' % key
- # Remove access keys
- value = sourceData[stringID]
- match = re.search(r'^(.*?)\s*\(&.\)$', value)
- if match:
- value = match.group(1)
- else:
- index = value.find('&')
- if index >= 0:
- value = value[0:index] + value[index + 1:]
- data[key] = {'message': value}
+ set_translation(data, key, sourceData, stringID)
except Exception as e:
print 'Warning: error importing locale data from %s: %s' % (sourceFile, e)
@@ -380,7 +406,7 @@ def createBuild(baseDir, type='chrome', outFile=None, buildNum=None, releaseBuil
)
if metadata.has_section('import_locales'):
- importGeckoLocales(params, files)
+ import_locales(params, files)
files['manifest.json'] = createManifest(params, files)
if type == 'chrome':
« no previous file with comments | « no previous file | packagerEdge.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld