| OLD | NEW |
| 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, os, re, json, struct | 7 import sys |
| 8 import os |
| 9 import re |
| 10 import json |
| 11 import struct |
| 12 import io |
| 8 from StringIO import StringIO | 13 from StringIO import StringIO |
| 9 | 14 |
| 10 import packager | 15 import packager |
| 11 from packager import readMetadata, getMetadataPath, getDefaultFileName, getBuild
Version, getTemplate, Files | 16 from packager import readMetadata, getMetadataPath, getDefaultFileName, getBuild
Version, getTemplate, Files |
| 12 | 17 |
| 13 defaultLocale = 'en_US' | 18 defaultLocale = 'en_US' |
| 14 | 19 |
| 15 def getIgnoredFiles(params): | 20 def getIgnoredFiles(params): |
| 16 result = set(('store.description',)) | 21 result = set(('store.description',)) |
| 17 | 22 |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 | 160 |
| 156 def toJson(data): | 161 def toJson(data): |
| 157 return json.dumps( | 162 return json.dumps( |
| 158 data, ensure_ascii=False, sort_keys=True, | 163 data, ensure_ascii=False, sort_keys=True, |
| 159 indent=2, separators=(',', ': ') | 164 indent=2, separators=(',', ': ') |
| 160 ).encode('utf-8') + '\n' | 165 ).encode('utf-8') + '\n' |
| 161 | 166 |
| 162 def importGeckoLocales(params, files): | 167 def importGeckoLocales(params, files): |
| 163 import localeTools | 168 import localeTools |
| 164 | 169 |
| 165 localeCodeMapping = { | 170 # FIXME: localeTools doesn't use real Chrome locales, it uses dash as |
| 166 'ar': 'ar', | 171 # separator instead. |
| 167 'bg': 'bg', | 172 convert_locale_code = lambda code: code.replace('-', '_') |
| 168 'ca': 'ca', | |
| 169 'cs': 'cs', | |
| 170 'da': 'da', | |
| 171 'de': 'de', | |
| 172 'el': 'el', | |
| 173 'en-US': 'en_US', | |
| 174 'en-GB': 'en_GB', | |
| 175 'es-ES': 'es', | |
| 176 'es-AR': 'es_419', | |
| 177 'et': 'et', | |
| 178 'fi': 'fi', | |
| 179 # '': 'fil', ??? | |
| 180 'fr': 'fr', | |
| 181 'he': 'he', | |
| 182 'hi-IN': 'hi', | |
| 183 'hr': 'hr', | |
| 184 'hu': 'hu', | |
| 185 'id': 'id', | |
| 186 'it': 'it', | |
| 187 'ja': 'ja', | |
| 188 'ko': 'ko', | |
| 189 'lt': 'lt', | |
| 190 'lv': 'lv', | |
| 191 'nl': 'nl', | |
| 192 # 'nb-NO': 'no', ??? | |
| 193 'pl': 'pl', | |
| 194 'pt-BR': 'pt_BR', | |
| 195 'pt-PT': 'pt_PT', | |
| 196 'ro': 'ro', | |
| 197 'ru': 'ru', | |
| 198 'sk': 'sk', | |
| 199 'sl': 'sl', | |
| 200 'sr': 'sr', | |
| 201 'sv-SE': 'sv', | |
| 202 'th': 'th', | |
| 203 'tr': 'tr', | |
| 204 'uk': 'uk', | |
| 205 'vi': 'vi', | |
| 206 'zh-CN': 'zh_CN', | |
| 207 'zh-TW': 'zh_TW', | |
| 208 } | |
| 209 | 173 |
| 210 for source, target in localeCodeMapping.iteritems(): | 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
} |
| 177 |
| 178 # Convert values to Crowdin locales first (use Chrome => Crowdin mapping). |
| 179 for chrome_locale, crowdin_locale in localeTools.langMappingChrome.iteritems()
: |
| 180 locale_mapping[convert_locale_code(chrome_locale)] = crowdin_locale |
| 181 |
| 182 # Now convert values to Gecko locales (use Gecko => Crowdin mapping). |
| 183 reverse_mapping = {v: k for k, v in locale_mapping.iteritems()} |
| 184 for gecko_locale, crowdin_locale in localeTools.langMappingGecko.iteritems(): |
| 185 if crowdin_locale in reverse_mapping: |
| 186 locale_mapping[reverse_mapping[crowdin_locale]] = gecko_locale |
| 187 |
| 188 for target, source in locale_mapping.iteritems(): |
| 211 targetFile = '_locales/%s/messages.json' % target | 189 targetFile = '_locales/%s/messages.json' % target |
| 190 if not targetFile in files: |
| 191 continue |
| 212 | 192 |
| 213 for item in params['metadata'].items('import_locales'): | 193 for item in params['metadata'].items('import_locales'): |
| 214 fileName, keys = item | 194 fileName, keys = item |
| 215 parts = map(lambda n: source if n == '*' else n, fileName.split('/')) | 195 parts = map(lambda n: source if n == '*' else n, fileName.split('/')) |
| 216 sourceFile = os.path.join(os.path.dirname(item.source), *parts) | 196 sourceFile = os.path.join(os.path.dirname(item.source), *parts) |
| 217 incompleteMarker = os.path.join(os.path.dirname(sourceFile), '.incomplete'
) | 197 incompleteMarker = os.path.join(os.path.dirname(sourceFile), '.incomplete'
) |
| 218 if not os.path.exists(sourceFile) or os.path.exists(incompleteMarker): | 198 if not os.path.exists(sourceFile) or os.path.exists(incompleteMarker): |
| 219 continue | 199 continue |
| 220 | 200 |
| 221 data = {} | 201 data = json.loads(files[targetFile].decode('utf-8')) |
| 222 if targetFile in files: | |
| 223 data = json.loads(files[targetFile].decode('utf-8')) | |
| 224 | 202 |
| 225 try: | 203 try: |
| 226 sourceData = localeTools.readFile(sourceFile) | 204 if sourceFile.endswith('.json'): |
| 205 with io.open(sourceFile, 'r', encoding='utf-8') as handle: |
| 206 sourceData = {k: v['message'] for k, v in json.load(handle).iteritem
s()} |
| 207 else: |
| 208 sourceData = localeTools.readFile(sourceFile) |
| 227 | 209 |
| 228 # Resolve wildcard imports | 210 # Resolve wildcard imports |
| 229 if keys == '*' or keys == '=*': | 211 if keys == '*' or keys == '=*': |
| 230 importList = sourceData.keys() | 212 importList = sourceData.keys() |
| 231 importList = filter(lambda k: not k.startswith('_'), importList) | 213 importList = filter(lambda k: not k.startswith('_'), importList) |
| 232 if keys == '=*': | 214 if keys == '=*': |
| 233 importList = map(lambda k: '=' + k, importList) | 215 importList = map(lambda k: '=' + k, importList) |
| 234 keys = ' '.join(importList) | 216 keys = ' '.join(importList) |
| 235 | 217 |
| 236 for stringID in re.split(r'\s+', keys): | 218 for stringID in re.split(r'\s+', keys): |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 'lib/info.js' not in files): | 372 'lib/info.js' not in files): |
| 391 files['lib/info.js'] = createInfoModule(params) | 373 files['lib/info.js'] = createInfoModule(params) |
| 392 | 374 |
| 393 zipdata = files.zipToString() | 375 zipdata = files.zipToString() |
| 394 signature = None | 376 signature = None |
| 395 pubkey = None | 377 pubkey = None |
| 396 if keyFile != None: | 378 if keyFile != None: |
| 397 signature = signBinary(zipdata, keyFile) | 379 signature = signBinary(zipdata, keyFile) |
| 398 pubkey = getPublicKey(keyFile) | 380 pubkey = getPublicKey(keyFile) |
| 399 writePackage(outFile, pubkey, signature, zipdata) | 381 writePackage(outFile, pubkey, signature, zipdata) |
| OLD | NEW |