Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 # This Source Code Form is subject to the terms of the Mozilla Public | 1 # This Source Code Form is subject to the terms of the Mozilla Public |
2 # License, v. 2.0. If a copy of the MPL was not distributed with this | 2 # License, v. 2.0. If a copy of the MPL was not distributed with this |
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/. | 3 # file, You can obtain one at http://mozilla.org/MPL/2.0/. |
4 | 4 |
5 import errno | 5 import errno |
6 import io | 6 import io |
7 import json | 7 import json |
8 import os | 8 import os |
9 import re | 9 import re |
10 from StringIO import StringIO | 10 from StringIO import StringIO |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
184 | 184 |
185 | 185 |
186 def toJson(data): | 186 def toJson(data): |
187 return json.dumps( | 187 return json.dumps( |
188 data, ensure_ascii=False, sort_keys=True, | 188 data, ensure_ascii=False, sort_keys=True, |
189 indent=2, separators=(',', ': ') | 189 indent=2, separators=(',', ': ') |
190 ).encode('utf-8') + '\n' | 190 ).encode('utf-8') + '\n' |
191 | 191 |
192 | 192 |
193 def import_string_webext(data, key, source): | 193 def import_string_webext(data, key, source): |
194 """Import source-dict into data.""" | 194 """Import a single translation from the source dictionary 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.
| |
195 data[key] = source | 195 data[key] = source |
196 | 196 |
197 | 197 |
198 def import_string_gecko(data, key, value): | 198 def import_string_gecko(data, key, value): |
199 """Import Gecko-style locales into data. | 199 """Import Gecko-style locales into data. |
200 | 200 |
201 Only sets {'message': value} in the data-dictionary, after stripping | 201 Only sets {'message': value} in the data-dictionary, after stripping |
202 undesired Gecko-style access keys. | 202 undesired Gecko-style access keys. |
203 """ | 203 """ |
204 match = re.search(r'^(.*?)\s*\(&.\)$', value) | 204 match = re.search(r'^(.*?)\s*\(&.\)$', value) |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
246 if not os.path.exists(sourceFile) or os.path.exists(incompleteMarker ): | 246 if not os.path.exists(sourceFile) or os.path.exists(incompleteMarker ): |
247 continue | 247 continue |
248 | 248 |
249 data = json.loads(files[targetFile].decode('utf-8')) | 249 data = json.loads(files[targetFile].decode('utf-8')) |
250 | 250 |
251 try: | 251 try: |
252 # The WebExtensions (.json) and Gecko format provide | 252 # The WebExtensions (.json) and Gecko format provide |
253 # translations differently and/or provide additional | 253 # translations differently and/or provide additional |
254 # information like e.g. "placeholders". We want to adhere to | 254 # information like e.g. "placeholders". We want to adhere to |
255 # that and preserve the addtional info. | 255 # that and preserve the addtional info. |
256 | |
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.
| |
257 if sourceFile.endswith('.json'): | 256 if sourceFile.endswith('.json'): |
258 with io.open(sourceFile, 'r', encoding='utf-8') as handle: | 257 with io.open(sourceFile, 'r', encoding='utf-8') as handle: |
259 sourceData = json.load(handle) | 258 sourceData = json.load(handle) |
260 import_string = import_string_webext | 259 import_string = import_string_webext |
261 else: | 260 else: |
262 sourceData = localeTools.readFile(sourceFile) | 261 sourceData = localeTools.readFile(sourceFile) |
263 import_string = import_string_gecko | 262 import_string = import_string_gecko |
264 | 263 |
265 # Resolve wildcard imports | 264 # Resolve wildcard imports |
266 if keys == '*' or keys == '=*': | 265 if keys == '*' or keys == '=*': |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
417 params, 'testIndex.html.tmpl', ('general', 'testScripts') | 416 params, 'testIndex.html.tmpl', ('general', 'testScripts') |
418 ) | 417 ) |
419 | 418 |
420 zipdata = files.zipToString() | 419 zipdata = files.zipToString() |
421 signature = None | 420 signature = None |
422 pubkey = None | 421 pubkey = None |
423 if keyFile != None: | 422 if keyFile != None: |
424 signature = signBinary(zipdata, keyFile) | 423 signature = signBinary(zipdata, keyFile) |
425 pubkey = getPublicKey(keyFile) | 424 pubkey = getPublicKey(keyFile) |
426 writePackage(outFile, pubkey, signature, zipdata) | 425 writePackage(outFile, pubkey, signature, zipdata) |
LEFT | RIGHT |