 Issue 29517660:
  Issue 5477 - Import everything from imported locales  (Closed)
    
  
    Issue 29517660:
  Issue 5477 - Import everything from imported locales  (Closed) 
  | Index: packagerChrome.py | 
| diff --git a/packagerChrome.py b/packagerChrome.py | 
| index 3e1a452a1a5b79fa7ff7316930ac911aab8162a6..d8f15d179f8a6947fcac0411e2efc604315959ab 100644 | 
| --- a/packagerChrome.py | 
| +++ b/packagerChrome.py | 
| @@ -190,7 +190,29 @@ def toJson(data): | 
| ).encode('utf-8') + '\n' | 
| -def importGeckoLocales(params, files): | 
| +def import_string_webext(data, key, source): | 
| + """Import source-dict into data.""" | 
| 
Wladimir Palant
2017/08/21 13:59:05
Nit: "Import a single translation from source dict
 
tlucas
2017/08/22 08:00:50
Done.
 | 
| + 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): | 
| import localeTools | 
| # FIXME: localeTools doesn't use real Chrome locales, it uses dash as | 
| @@ -227,11 +249,18 @@ def importGeckoLocales(params, files): | 
| data = json.loads(files[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. | 
| + | 
| 
Sebastian Noack
2017/08/22 07:38:11
Nit: The blank line here seems out of place.
 
tlucas
2017/08/22 08:00:50
Done.
 | 
| 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) | 
| + import_string = import_string_webext | 
| else: | 
| sourceData = localeTools.readFile(sourceFile) | 
| + import_string = import_string_gecko | 
| # Resolve wildcard imports | 
| if keys == '*' or keys == '=*': | 
| @@ -255,16 +284,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} | 
| + import_string(data, key, sourceData[stringID]) | 
| 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': |