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

Delta Between Two Patch Sets: packagerChrome.py

Issue 29561557: Issue 5763 - Target languages supported by Firefox (Closed)
Left Patch Set: Adressed Vasily's comments Created Oct. 2, 2017, 10:57 p.m.
Right Patch Set: Fixed undefined variable, put URLS in globals, removed redundand flake8 ignores Created Oct. 5, 2017, 8:54 p.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 | « localeTools.py ('k') | tox.ini » ('j') | tox.ini » ('J')
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
11 import struct 11 import struct
12 import sys 12 import sys
13 import collections 13 import collections
14 import glob
14 15
15 from packager import (readMetadata, getDefaultFileName, getBuildVersion, 16 from packager import (readMetadata, getDefaultFileName, getBuildVersion,
16 getTemplate, Files) 17 getTemplate, Files)
17 18
18 defaultLocale = 'en_US' 19 defaultLocale = 'en_US'
19 20
20 21
21 def getIgnoredFiles(params): 22 def getIgnoredFiles(params):
22 return {'store.description'} 23 return {'store.description'}
23 24
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 value = match.group(1) 207 value = match.group(1)
207 else: 208 else:
208 index = value.find('&') 209 index = value.find('&')
209 if index >= 0: 210 if index >= 0:
210 value = value[0:index] + value[index + 1:] 211 value = value[0:index] + value[index + 1:]
211 212
212 data[key] = {'message': value} 213 data[key] = {'message': value}
213 214
214 215
215 def import_locales(params, files): 216 def import_locales(params, files):
216 import localeTools 217 for item in params['metadata'].items('import_locales'):
217 218 filename, keys = item
218 # FIXME: localeTools doesn't use real Chrome locales, it uses dash as 219 for sourceFile in glob.glob(os.path.join(os.path.dirname(item.source),
219 # separator instead. 220 *filename.split('/'))):
220 convert_locale_code = lambda code: code.replace('-', '_') 221 parts = sourceFile.split(os.path.sep)
Sebastian Noack 2017/10/05 20:58:38 I just noticed that the variable "parts" is used b
tlucas 2017/10/06 08:53:53 Acknowledged.
221 222 locale = parts[-2].replace('-', '_')
222 # We need to map Chrome locales to Gecko locales. Start by mapping Chrome 223 targetFile = os.path.join('_locales', locale, 'messages.json')
223 # locales to themselves, merely with the dash as separator. 224 data = json.loads(files.get(targetFile, '{}').decode('utf-8'))
224 locale_mapping = {convert_locale_code(l): l for l in localeTools.chromeLocal es}
225
226 # Convert values to Crowdin locales first (use Chrome => Crowdin mapping).
227 for chrome_locale, crowdin_locale in localeTools.CROWDIN_LANG_MAPPING.iterit ems():
228 locale_mapping[convert_locale_code(chrome_locale)] = crowdin_locale
229
230 # Now convert values to Gecko locales (use Gecko => Crowdin mapping).
231 reverse_mapping = {v: k for k, v in locale_mapping.iteritems()}
232 for gecko_locale, crowdin_locale in localeTools.CROWDIN_LANG_MAPPING.iterite ms():
233 if crowdin_locale in reverse_mapping:
234 locale_mapping[reverse_mapping[crowdin_locale]] = gecko_locale
235
236 for target, source in locale_mapping.iteritems():
237 targetFile = '_locales/%s/messages.json' % target
238 if not targetFile in files:
239 continue
240
241 for item in params['metadata'].items('import_locales'):
242 fileName, keys = item
243 parts = map(lambda n: source if n == '*' else n, fileName.split('/') )
244 sourceFile = os.path.join(os.path.dirname(item.source), *parts)
245 incompleteMarker = os.path.join(os.path.dirname(sourceFile), '.incom plete')
246 if not os.path.exists(sourceFile) or os.path.exists(incompleteMarker ):
247 continue
248
249 data = json.loads(files[targetFile].decode('utf-8'))
250 225
251 try: 226 try:
252 # The WebExtensions (.json) and Gecko format provide 227 # The WebExtensions (.json) and Gecko format provide
253 # translations differently and/or provide additional 228 # translations differently and/or provide additional
254 # information like e.g. "placeholders". We want to adhere to 229 # information like e.g. "placeholders". We want to adhere to
255 # that and preserve the addtional info. 230 # that and preserve the addtional info.
256 if sourceFile.endswith('.json'): 231 if sourceFile.endswith('.json'):
257 with io.open(sourceFile, 'r', encoding='utf-8') as handle: 232 with io.open(sourceFile, 'r', encoding='utf-8') as handle:
258 sourceData = json.load(handle) 233 sourceData = json.load(handle)
259 import_string = import_string_webext 234 import_string = import_string_webext
260 else: 235 else:
236 import localeTools
261 sourceData = localeTools.readFile(sourceFile) 237 sourceData = localeTools.readFile(sourceFile)
262 import_string = import_string_gecko 238 import_string = import_string_gecko
263 239
264 # Resolve wildcard imports 240 # Resolve wildcard imports
265 if keys == '*' or keys == '=*': 241 if keys == '*' or keys == '=*':
266 importList = sourceData.keys() 242 importList = sourceData.keys()
267 importList = filter(lambda k: not k.startswith('_'), importL ist) 243 importList = filter(lambda k: not k.startswith('_'), importL ist)
268 if keys == '=*': 244 if keys == '=*':
269 importList = map(lambda k: '=' + k, importList) 245 importList = map(lambda k: '=' + k, importList)
270 keys = ' '.join(importList) 246 keys = ' '.join(importList)
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 params, 'testIndex.html.tmpl', ('general', 'testScripts') 402 params, 'testIndex.html.tmpl', ('general', 'testScripts')
427 ) 403 )
428 404
429 zipdata = files.zipToString() 405 zipdata = files.zipToString()
430 signature = None 406 signature = None
431 pubkey = None 407 pubkey = None
432 if keyFile != None: 408 if keyFile != None:
433 signature = signBinary(zipdata, keyFile) 409 signature = signBinary(zipdata, keyFile)
434 pubkey = getPublicKey(keyFile) 410 pubkey = getPublicKey(keyFile)
435 writePackage(outFile, pubkey, signature, zipdata) 411 writePackage(outFile, pubkey, signature, zipdata)
LEFTRIGHT

Powered by Google App Engine
This is Rietveld