Index: packagerChrome.py |
diff --git a/packagerChrome.py b/packagerChrome.py |
index 3e1a452a1a5b79fa7ff7316930ac911aab8162a6..23ebcac218d148b7b0aae4e139118bf50d19d206 100644 |
--- a/packagerChrome.py |
+++ b/packagerChrome.py |
@@ -190,7 +190,7 @@ def toJson(data): |
).encode('utf-8') + '\n' |
-def importGeckoLocales(params, files): |
+def import_locales(params, files): |
import localeTools |
# FIXME: localeTools doesn't use real Chrome locales, it uses dash as |
@@ -227,12 +227,39 @@ def importGeckoLocales(params, files): |
data = json.loads(files[targetFile].decode('utf-8')) |
try: |
+ # .json and other formats provide translations differently and |
+ # / or provide additional information like e.g. "placeholders". |
+ # 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) |
+ |
+ def get_value(data, stringID): |
+ return data[stringID]['message'] |
+ |
+ def set_translation(data, key, value, source, stringID): |
+ data[key] = {'messages': value} |
+ for k, v in source[stringID].items(): |
+ data[key].setdefault(k, v) |
else: |
sourceData = localeTools.readFile(sourceFile) |
+ def get_value(data, stringID): |
+ # Remove access keys from possible gecko-style |
+ # translations |
+ value = data[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:] |
+ return value |
+ |
+ def set_translation(data, key, value, *args): |
+ data[key] = {'message': value} |
+ |
# Resolve wildcard imports |
if keys == '*' or keys == '=*': |
importList = sourceData.keys() |
@@ -255,16 +282,9 @@ 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} |
+ value = get_value(sourceData, stringID) |
+ |
+ set_translation(data, key, value, sourceData, stringID) |
Sebastian Noack
2017/08/18 13:54:48
It seems the logic could be further simplified by
tlucas
2017/08/18 14:35:42
Done.
|
except Exception as e: |
print 'Warning: error importing locale data from %s: %s' % (sourceFile, e) |
@@ -380,7 +400,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': |