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

Side by Side Diff: localeTools.py

Issue 29345279: Noissue - Adapt quotes for compliance with our coding style in buildtools (Closed)
Patch Set: Created May 29, 2016, 1:27 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ensure_dependencies.py ('k') | packager.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 re 5 import re
6 import os 6 import os
7 import sys 7 import sys
8 import codecs 8 import codecs
9 import json 9 import json
10 import urllib 10 import urllib
(...skipping 19 matching lines...) Expand all
30 30
31 langMappingChrome = { 31 langMappingChrome = {
32 'es-419': 'es-MX', 32 'es-419': 'es-MX',
33 'es': 'es-ES', 33 'es': 'es-ES',
34 'sv': 'sv-SE', 34 'sv': 'sv-SE',
35 'ml': 'ml-IN', 35 'ml': 'ml-IN',
36 'gu': 'gu-IN', 36 'gu': 'gu-IN',
37 } 37 }
38 38
39 chromeLocales = [ 39 chromeLocales = [
40 "am", 40 'am',
41 "ar", 41 'ar',
42 "bg", 42 'bg',
43 "bn", 43 'bn',
44 "ca", 44 'ca',
45 "cs", 45 'cs',
46 "da", 46 'da',
47 "de", 47 'de',
48 "el", 48 'el',
49 "en-GB", 49 'en-GB',
50 "en-US", 50 'en-US',
51 "es-419", 51 'es-419',
52 "es", 52 'es',
53 "et", 53 'et',
54 "fa", 54 'fa',
55 "fi", 55 'fi',
56 "fil", 56 'fil',
57 "fr", 57 'fr',
58 "gu", 58 'gu',
59 "he", 59 'he',
60 "hi", 60 'hi',
61 "hr", 61 'hr',
62 "hu", 62 'hu',
63 "id", 63 'id',
64 "it", 64 'it',
65 "ja", 65 'ja',
66 "kn", 66 'kn',
67 "ko", 67 'ko',
68 "lt", 68 'lt',
69 "lv", 69 'lv',
70 "ml", 70 'ml',
71 "mr", 71 'mr',
72 "ms", 72 'ms',
73 "nb", 73 'nb',
74 "nl", 74 'nl',
75 "pl", 75 'pl',
76 "pt-BR", 76 'pt-BR',
77 "pt-PT", 77 'pt-PT',
78 "ro", 78 'ro',
79 "ru", 79 'ru',
80 "sk", 80 'sk',
81 "sl", 81 'sl',
82 "sr", 82 'sr',
83 "sv", 83 'sv',
84 "sw", 84 'sw',
85 "ta", 85 'ta',
86 "te", 86 'te',
87 "th", 87 'th',
88 "tr", 88 'tr',
89 "uk", 89 'uk',
90 "vi", 90 'vi',
91 "zh-CN", 91 'zh-CN',
92 "zh-TW", 92 'zh-TW',
93 ] 93 ]
94 94
95 95
96 class OrderedDict(dict): 96 class OrderedDict(dict):
97 def __init__(self): 97 def __init__(self):
98 self.__order = [] 98 self.__order = []
99 99
100 def __setitem__(self, key, value): 100 def __setitem__(self, key, value):
101 self.__order.append(key) 101 self.__order.append(key)
102 dict.__setitem__(self, key, value) 102 dict.__setitem__(self, key, value)
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 262
263 263
264 def preprocessChromeLocale(path, metadata, isMaster): 264 def preprocessChromeLocale(path, metadata, isMaster):
265 fileHandle = codecs.open(path, 'rb', encoding='utf-8') 265 fileHandle = codecs.open(path, 'rb', encoding='utf-8')
266 data = json.load(fileHandle) 266 data = json.load(fileHandle)
267 fileHandle.close() 267 fileHandle.close()
268 268
269 for key, value in data.iteritems(): 269 for key, value in data.iteritems():
270 if isMaster: 270 if isMaster:
271 # Make sure the key name is listed in the description 271 # Make sure the key name is listed in the description
272 if "description" in value: 272 if 'description' in value:
273 value["description"] = "%s: %s" % (key, value["description"]) 273 value['description'] = '%s: %s' % (key, value['description'])
274 else: 274 else:
275 value["description"] = key 275 value['description'] = key
276 else: 276 else:
277 # Delete description from translations 277 # Delete description from translations
278 if "description" in value: 278 if 'description' in value:
279 del value["description"] 279 del value['description']
280 280
281 return json.dumps(data, ensure_ascii=False, sort_keys=True, indent=2) 281 return json.dumps(data, ensure_ascii=False, sort_keys=True, indent=2)
282 282
283 283
284 def postprocessChromeLocale(path, data): 284 def postprocessChromeLocale(path, data):
285 parsed = json.loads(data) 285 parsed = json.loads(data)
286 if isinstance(parsed, list): 286 if isinstance(parsed, list):
287 return 287 return
288 288
289 # Delete description from translations 289 # Delete description from translations
290 for key, value in parsed.iteritems(): 290 for key, value in parsed.iteritems():
291 if "description" in value: 291 if 'description' in value:
292 del value["description"] 292 del value['description']
293 293
294 file = codecs.open(path, 'wb', encoding='utf-8') 294 file = codecs.open(path, 'wb', encoding='utf-8')
295 json.dump(parsed, file, ensure_ascii=False, sort_keys=True, indent=2, separa tors=(',', ': ')) 295 json.dump(parsed, file, ensure_ascii=False, sort_keys=True, indent=2, separa tors=(',', ': '))
296 file.close() 296 file.close()
297 297
298 298
299 def setupTranslations(localeConfig, projectName, key): 299 def setupTranslations(localeConfig, projectName, key):
300 # Make a new set from the locales list, mapping to Crowdin friendly format 300 # Make a new set from the locales list, mapping to Crowdin friendly format
301 locales = {mapLocale(localeConfig['name_format'], locale) 301 locales = {mapLocale(localeConfig['name_format'], locale)
302 for locale in localeConfig['locales']} 302 for locale in localeConfig['locales']}
(...skipping 12 matching lines...) Expand all
315 if match.group(0).find('Install Language Pack') >= 0: 315 if match.group(0).find('Install Language Pack') >= 0:
316 match2 = re.search(r'lang="([\w\-]+)"', match.group(0)) 316 match2 = re.search(r'lang="([\w\-]+)"', match.group(0))
317 if match2: 317 if match2:
318 locales.add(mapLocale('BCP-47', match2.group(1))) 318 locales.add(mapLocale('BCP-47', match2.group(1)))
319 319
320 allowed = set() 320 allowed = set()
321 allowedLocales = urllib2.urlopen('http://crowdin.net/page/language-codes').r ead() 321 allowedLocales = urllib2.urlopen('http://crowdin.net/page/language-codes').r ead()
322 for match in re.finditer(r'<tr>\s*<td\b[^<>]*>([\w\-]+)</td>', allowedLocale s, re.S): 322 for match in re.finditer(r'<tr>\s*<td\b[^<>]*>([\w\-]+)</td>', allowedLocale s, re.S):
323 allowed.add(match.group(1)) 323 allowed.add(match.group(1))
324 if not allowed.issuperset(locales): 324 if not allowed.issuperset(locales):
325 print 'Warning, following locales aren\'t allowed by server: ' + ', '.jo in(locales - allowed) 325 print "Warning, following locales aren't allowed by server: " + ', '.joi n(locales - allowed)
326 326
327 locales = list(locales & allowed) 327 locales = list(locales & allowed)
328 locales.sort() 328 locales.sort()
329 params = urllib.urlencode([('languages[]', locale) for locale in locales]) 329 params = urllib.urlencode([('languages[]', locale) for locale in locales])
330 result = urllib2.urlopen('http://api.crowdin.net/api/project/%s/edit-project ?key=%s' % (projectName, key), params).read() 330 result = urllib2.urlopen('http://api.crowdin.net/api/project/%s/edit-project ?key=%s' % (projectName, key), params).read()
331 if result.find('<success') < 0: 331 if result.find('<success') < 0:
332 raise Exception('Server indicated that the operation was not successful\ n' + result) 332 raise Exception('Server indicated that the operation was not successful\ n' + result)
333 333
334 334
335 def postFiles(files, url): 335 def postFiles(files, url):
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 482
483 # Remove any extra files 483 # Remove any extra files
484 for dir, files in dirs.iteritems(): 484 for dir, files in dirs.iteritems():
485 baseDir = os.path.join(localeConfig['base_path'], dir) 485 baseDir = os.path.join(localeConfig['base_path'], dir)
486 if not os.path.exists(baseDir): 486 if not os.path.exists(baseDir):
487 continue 487 continue
488 for file in os.listdir(baseDir): 488 for file in os.listdir(baseDir):
489 path = os.path.join(baseDir, file) 489 path = os.path.join(baseDir, file)
490 if os.path.isfile(path) and (file.endswith('.json') or file.endswith ('.properties') or file.endswith('.dtd')) and not file in files: 490 if os.path.isfile(path) and (file.endswith('.json') or file.endswith ('.properties') or file.endswith('.dtd')) and not file in files:
491 os.remove(path) 491 os.remove(path)
OLDNEW
« no previous file with comments | « ensure_dependencies.py ('k') | packager.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld