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

Delta Between Two Patch Sets: packagerChrome.py

Issue 29517660: Issue 5477 - Import everything from imported locales (Closed)
Left Patch Set: Created Aug. 18, 2017, 3:52 p.m.
Right Patch Set: Created Aug. 22, 2017, 7:59 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | packagerEdge.py » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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
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 """Overwrites data[key] with source.""" 194 """Import a single translation from the source dictionary into data"""
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 """Only sets {'message': value} in data-dictionary, after stripping 199 """Import Gecko-style locales into data.
Vasily Kuznetsov 2017/08/21 10:43:18 Do you think it would be difficult to make this do
tlucas 2017/08/21 11:33:01 Do you mean full conformity, including params? For
Vasily Kuznetsov 2017/08/21 11:53:15 Yeah, just rephrase and reformat where appropriate
tlucas 2017/08/21 12:28:50 Done.
200 undesired gecko-style access keys. 200
201 Only sets {'message': value} in the data-dictionary, after stripping
202 undesired Gecko-style access keys.
201 """ 203 """
202
203 # Remove access keys from possible gecko-style
Wladimir Palant 2017/08/21 10:57:21 Nit: Gecko should be capitalized (here and in the
tlucas 2017/08/21 11:33:00 Acknowledged.
tlucas 2017/08/21 12:28:50 Done.
204 # translations
205 match = re.search(r'^(.*?)\s*\(&.\)$', value) 204 match = re.search(r'^(.*?)\s*\(&.\)$', value)
Wladimir Palant 2017/08/21 10:57:21 For reference, the regexp used by Firefox code is
tlucas 2017/08/21 11:33:00 Acknowledged.
206 if match: 205 if match:
207 value = match.group(1) 206 value = match.group(1)
208 else: 207 else:
209 index = value.find('&') 208 index = value.find('&')
210 if index >= 0: 209 if index >= 0:
211 value = value[0:index] + value[index + 1:] 210 value = value[0:index] + value[index + 1:]
212 211
213 data[key] = {'message': value} 212 data[key] = {'message': value}
214 213
215 214
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 if not os.path.exists(sourceFile) or os.path.exists(incompleteMarker ): 246 if not os.path.exists(sourceFile) or os.path.exists(incompleteMarker ):
248 continue 247 continue
249 248
250 data = json.loads(files[targetFile].decode('utf-8')) 249 data = json.loads(files[targetFile].decode('utf-8'))
251 250
252 try: 251 try:
253 # The WebExtensions (.json) and Gecko format provide 252 # The WebExtensions (.json) and Gecko format provide
254 # translations differently and/or provide additional 253 # translations differently and/or provide additional
255 # information like e.g. "placeholders". We want to adhere to 254 # information like e.g. "placeholders". We want to adhere to
256 # that and preserve the addtional info. 255 # that and preserve the addtional info.
257
258 if sourceFile.endswith('.json'): 256 if sourceFile.endswith('.json'):
259 with io.open(sourceFile, 'r', encoding='utf-8') as handle: 257 with io.open(sourceFile, 'r', encoding='utf-8') as handle:
260 sourceData = json.load(handle) 258 sourceData = json.load(handle)
261
Vasily Kuznetsov 2017/08/21 10:43:18 I don't feel very strong about it, but it seems th
tlucas 2017/08/21 11:33:01 Acknowledged.
tlucas 2017/08/21 12:28:50 Done.
262 import_string = import_string_webext 259 import_string = import_string_webext
263 else: 260 else:
264 sourceData = localeTools.readFile(sourceFile) 261 sourceData = localeTools.readFile(sourceFile)
265
266 import_string = import_string_gecko 262 import_string = import_string_gecko
267 263
268 # Resolve wildcard imports 264 # Resolve wildcard imports
269 if keys == '*' or keys == '=*': 265 if keys == '*' or keys == '=*':
270 importList = sourceData.keys() 266 importList = sourceData.keys()
271 importList = filter(lambda k: not k.startswith('_'), importL ist) 267 importList = filter(lambda k: not k.startswith('_'), importL ist)
272 if keys == '=*': 268 if keys == '=*':
273 importList = map(lambda k: '=' + k, importList) 269 importList = map(lambda k: '=' + k, importList)
274 keys = ' '.join(importList) 270 keys = ' '.join(importList)
275 271
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 params, 'testIndex.html.tmpl', ('general', 'testScripts') 416 params, 'testIndex.html.tmpl', ('general', 'testScripts')
421 ) 417 )
422 418
423 zipdata = files.zipToString() 419 zipdata = files.zipToString()
424 signature = None 420 signature = None
425 pubkey = None 421 pubkey = None
426 if keyFile != None: 422 if keyFile != None:
427 signature = signBinary(zipdata, keyFile) 423 signature = signBinary(zipdata, keyFile)
428 pubkey = getPublicKey(keyFile) 424 pubkey = getPublicKey(keyFile)
429 writePackage(outFile, pubkey, signature, zipdata) 425 writePackage(outFile, pubkey, signature, zipdata)
LEFTRIGHT
« no previous file | packagerEdge.py » ('j') | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld