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

Delta Between Two Patch Sets: packagerChrome.py

Issue 5307739131609088: Issue 1709 - Allow importing Chrome-style locales in Chrome extensions (Closed)
Left Patch Set: Created Dec. 16, 2014, 11:11 p.m.
Right Patch Set: Removed code duplication Created Dec. 17, 2014, 2:58 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 | « no previous file | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 # coding: utf-8 1 # coding: utf-8
2 2
3 # This Source Code Form is subject to the terms of the Mozilla Public 3 # This Source Code Form is subject to the terms of the Mozilla Public
4 # License, v. 2.0. If a copy of the MPL was not distributed with this 4 # License, v. 2.0. If a copy of the MPL was not distributed with this
5 # file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 6
7 import sys 7 import sys
8 import os 8 import os
9 import re 9 import re
10 import json 10 import json
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 160
161 def toJson(data): 161 def toJson(data):
162 return json.dumps( 162 return json.dumps(
163 data, ensure_ascii=False, sort_keys=True, 163 data, ensure_ascii=False, sort_keys=True,
164 indent=2, separators=(',', ': ') 164 indent=2, separators=(',', ': ')
165 ).encode('utf-8') + '\n' 165 ).encode('utf-8') + '\n'
166 166
167 def importGeckoLocales(params, files): 167 def importGeckoLocales(params, files):
168 import localeTools 168 import localeTools
169 169
170 # We need to map Gecko locales to Chrome locales. Start by mapping Chrome 170 # FIXME: localeTools doesn't use real Chrome locales, it uses dash as
171 # locales to themselves. 171 # separator instead.
172 locale_mapping = {l: l for l in localeTools.chromeLocales} 172 convert_locale_code = lambda code: code.replace('-', '_')
173
174 # We need to map Chrome locales to Gecko locales. Start by mapping Chrome
175 # locales to themselves, merely with the dash as separator.
176 locale_mapping = {convert_locale_code(l): l for l in localeTools.chromeLocales }
173 177
174 # Convert values to Crowdin locales first (use Chrome => Crowdin mapping). 178 # Convert values to Crowdin locales first (use Chrome => Crowdin mapping).
175 for chrome_locale, crowdin_locale in localeTools.langMappingChrome.iteritems() : 179 for chrome_locale, crowdin_locale in localeTools.langMappingChrome.iteritems() :
176 locale_mapping[chrome_locale] = crowdin_locale 180 locale_mapping[convert_locale_code(chrome_locale)] = crowdin_locale
177 181
178 # Now convert values to Gecko locales (use Gecko => Crowdin mapping). 182 # Now convert values to Gecko locales (use Gecko => Crowdin mapping).
179 def get_key(dict, value): 183 reverse_mapping = {v: k for k, v in locale_mapping.iteritems()}
Sebastian Noack 2014/12/17 09:04:06 Maybe I overlook something here? But it seems that
Wladimir Palant 2014/12/17 10:09:54 This will produce lots of duplicates - we need eac
Sebastian Noack 2014/12/17 10:18:36 Well, I were hoping to get rid of get_key() by doi
Wladimir Palant 2014/12/17 10:25:49 I think we can only do this by reversing the mappi
Sebastian Noack 2014/12/17 10:31:49 Both sounds good to me.
Wladimir Palant 2014/12/17 13:21:12 Ok, the current approach removes unnecessary steps
180 for k, v in dict.iteritems():
181 if v == value:
182 return k
183 return None
184
185 for gecko_locale, crowdin_locale in localeTools.langMappingGecko.iteritems(): 184 for gecko_locale, crowdin_locale in localeTools.langMappingGecko.iteritems():
186 chrome_locale = get_key(locale_mapping, crowdin_locale) 185 if crowdin_locale in reverse_mapping:
187 if chrome_locale is not None: 186 locale_mapping[reverse_mapping[crowdin_locale]] = gecko_locale
188 locale_mapping[chrome_locale] = gecko_locale 187
189 188 for target, source in locale_mapping.iteritems():
190 # Reverse mapping and make sure keys use underscores as separator
191 locale_mapping = {v: k.replace('-', '_') for k, v in locale_mapping.iteritems( )}
192
193 for source, target in locale_mapping.iteritems():
194 targetFile = '_locales/%s/messages.json' % target 189 targetFile = '_locales/%s/messages.json' % target
195 if not targetFile in files: 190 if not targetFile in files:
196 continue 191 continue
197 192
198 for item in params['metadata'].items('import_locales'): 193 for item in params['metadata'].items('import_locales'):
199 fileName, keys = item 194 fileName, keys = item
200 parts = map(lambda n: source if n == '*' else n, fileName.split('/')) 195 parts = map(lambda n: source if n == '*' else n, fileName.split('/'))
201 sourceFile = os.path.join(os.path.dirname(item.source), *parts) 196 sourceFile = os.path.join(os.path.dirname(item.source), *parts)
202 incompleteMarker = os.path.join(os.path.dirname(sourceFile), '.incomplete' ) 197 incompleteMarker = os.path.join(os.path.dirname(sourceFile), '.incomplete' )
203 if not os.path.exists(sourceFile) or os.path.exists(incompleteMarker): 198 if not os.path.exists(sourceFile) or os.path.exists(incompleteMarker):
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 'lib/info.js' not in files): 372 'lib/info.js' not in files):
378 files['lib/info.js'] = createInfoModule(params) 373 files['lib/info.js'] = createInfoModule(params)
379 374
380 zipdata = files.zipToString() 375 zipdata = files.zipToString()
381 signature = None 376 signature = None
382 pubkey = None 377 pubkey = None
383 if keyFile != None: 378 if keyFile != None:
384 signature = signBinary(zipdata, keyFile) 379 signature = signBinary(zipdata, keyFile)
385 pubkey = getPublicKey(keyFile) 380 pubkey = getPublicKey(keyFile)
386 writePackage(outFile, pubkey, signature, zipdata) 381 writePackage(outFile, pubkey, signature, zipdata)
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld