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

Unified Diff: packagerChrome.py

Issue 29562599: Issue 5751 - Removing legacy gecko support (Closed)
Patch Set: Tidy tox.ini, further simplify import_locales Created Oct. 6, 2017, 9:01 a.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
Index: packagerChrome.py
diff --git a/packagerChrome.py b/packagerChrome.py
index 5e6f550d20ef4e1e75ce00764082d55d13595726..f11b5dd8d4329946b2bb50c013c968a9a2d0f3f5 100644
--- a/packagerChrome.py
+++ b/packagerChrome.py
@@ -191,51 +191,18 @@ def toJson(data):
).encode('utf-8') + '\n'
-def import_string_webext(data, key, source):
- """Import a single translation from the source dictionary into data"""
- data[key] = source
-
-
-def import_string_gecko(data, key, value):
- """Import Gecko-style locales into data.
-
- Only sets {'message': value} in the data-dictionary, after stripping
- undesired Gecko-style access keys.
- """
- 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):
for item in params['metadata'].items('import_locales'):
filename, keys = item
for sourceFile in glob.glob(os.path.join(os.path.dirname(item.source),
*filename.split('/'))):
- parts = sourceFile.split(os.path.sep)
- locale = parts[-2].replace('-', '_')
+ locale = sourceFile.split(os.path.sep)[-2].replace('-', '_')
Sebastian Noack 2017/10/06 19:13:28 As pointed out on the review introducing this code
tlucas 2017/10/09 23:18:07 Done.
targetFile = os.path.join('_locales', locale, 'messages.json')
data = json.loads(files.get(targetFile, '{}').decode('utf-8'))
try:
- # The WebExtensions (.json) and Gecko format provide
- # translations differently and/or provide additional
- # information like e.g. "placeholders". We want to adhere to
- # that and preserve the addtional info.
- if sourceFile.endswith('.json'):
- with io.open(sourceFile, 'r', encoding='utf-8') as handle:
- sourceData = json.load(handle)
- import_string = import_string_webext
- else:
- import localeTools
- sourceData = localeTools.readFile(sourceFile)
- import_string = import_string_gecko
+ with io.open(sourceFile, 'r', encoding='utf-8') as handle:
+ sourceData = json.load(handle)
# Resolve wildcard imports
if keys == '*' or keys == '=*':
@@ -249,17 +216,13 @@ def import_locales(params, files):
noMangling = False
if stringID.startswith('='):
stringID = stringID[1:]
- noMangling = True
Sebastian Noack 2017/10/06 19:13:28 Since you are unsupporting the mangle feature, it
tlucas 2017/10/09 23:18:07 Done. I also adjusted the content in #5837 - feel
Sebastian Noack 2017/10/10 04:51:40 I don't see any change to the description of #5837
if stringID in sourceData:
- if noMangling:
- key = re.sub(r'\W', '_', stringID)
- else:
- key = re.sub(r'\..*', '', parts[-1]) + '_' + re.sub(r'\W', '_', stringID)
+ key = re.sub(r'\W', '_', stringID)
Sebastian Noack 2017/10/06 19:13:29 This should no longer be necessary either, as we w
tlucas 2017/10/09 23:18:07 A quick test verified your assumption, this line h
if key in data:
print 'Warning: locale string %s defined multiple times' % key
- import_string(data, key, sourceData[stringID])
+ data[key] = sourceData[stringID]
except Exception as e:
print 'Warning: error importing locale data from %s: %s' % (sourceFile, e)

Powered by Google App Engine
This is Rietveld