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

Delta Between Two Patch Sets: localeTools.py

Issue 29336281: Issue 2109 - Allow for translation of app independent repositories (Closed)
Left Patch Set: Addressed Wladimir's initial feedback Created Feb. 12, 2016, 6:23 p.m.
Right Patch Set: Fixed typo spotted during testing Created Feb. 13, 2016, 12:31 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 | « build.py ('k') | 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 re, os, sys, codecs, json, urllib, urllib2 7 import re, os, sys, codecs, json, urllib, urllib2
8 from StringIO import StringIO 8 from StringIO import StringIO
9 from ConfigParser import SafeConfigParser 9 from ConfigParser import SafeConfigParser
10 from zipfile import ZipFile 10 from zipfile import ZipFile
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 ) 389 )
390 390
391 def getTranslations(localeConfig, projectName, key): 391 def getTranslations(localeConfig, projectName, key):
392 result = urllib2.urlopen('http://api.crowdin.net/api/project/%s/export?key=%s' % (projectName, key)).read() 392 result = urllib2.urlopen('http://api.crowdin.net/api/project/%s/export?key=%s' % (projectName, key)).read()
393 if result.find('<success') < 0: 393 if result.find('<success') < 0:
394 raise Exception('Server indicated that the operation was not successful\n' + result) 394 raise Exception('Server indicated that the operation was not successful\n' + result)
395 395
396 result = urllib2.urlopen('http://api.crowdin.net/api/project/%s/download/all.z ip?key=%s' % (projectName, key)).read() 396 result = urllib2.urlopen('http://api.crowdin.net/api/project/%s/download/all.z ip?key=%s' % (projectName, key)).read()
397 zip = ZipFile(StringIO(result)) 397 zip = ZipFile(StringIO(result))
398 dirs = {} 398 dirs = {}
399
400 normalizedDefaultLocale = localeConfig['default_locale']
401 if localeConfig['name_format'] == 'ISO-15897':
402 normalizedDefaultLocale = normalizedDefaultLocale.replace('_', '-')
403 normalizedDefaultLocale = mapLocale(localeConfig['name_format'],
404 normalizedDefaultLocale)
405
399 for info in zip.infolist(): 406 for info in zip.infolist():
400 if not info.filename.endswith('.json'): 407 if not info.filename.endswith('.json'):
401 continue 408 continue
402 409
403 dir, file = os.path.split(info.filename) 410 dir, file = os.path.split(info.filename)
404 if not re.match(r'^[\w\-]+$', dir) or dir == localeConfig['default_locale']: 411 if not re.match(r'^[\w\-]+$', dir) or dir == normalizedDefaultLocale:
Wladimir Palant 2016/02/12 19:05:44 This check won't work correctly for Chrome, we wil
kzar 2016/02/12 19:40:26 Good point but I think we also need to replace the
405 continue 412 continue
406 if localeConfig['file_format'] == 'chrome-json' and file.count('.') == 1: 413 if localeConfig['file_format'] == 'chrome-json' and file.count('.') == 1:
407 origFile = file 414 origFile = file
408 else: 415 else:
409 origFile = re.sub(r'\.json$', '', file) 416 origFile = re.sub(r'\.json$', '', file)
410 if (localeConfig['file_format'] == 'gecko-dtd' and 417 if (localeConfig['file_format'] == 'gecko-dtd' and
411 not origFile.endswith('.dtd') and 418 not origFile.endswith('.dtd') and
412 not origFile.endswith('.properties')): 419 not origFile.endswith('.properties')):
413 continue 420 continue
414 421
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 454
448 # Remove any extra files 455 # Remove any extra files
449 for dir, files in dirs.iteritems(): 456 for dir, files in dirs.iteritems():
450 baseDir = os.path.join(localeConfig['base_path'], dir) 457 baseDir = os.path.join(localeConfig['base_path'], dir)
451 if not os.path.exists(baseDir): 458 if not os.path.exists(baseDir):
452 continue 459 continue
453 for file in os.listdir(baseDir): 460 for file in os.listdir(baseDir):
454 path = os.path.join(baseDir, file) 461 path = os.path.join(baseDir, file)
455 if os.path.isfile(path) and (file.endswith('.json') or file.endswith('.pro perties') or file.endswith('.dtd')) and not file in files: 462 if os.path.isfile(path) and (file.endswith('.json') or file.endswith('.pro perties') or file.endswith('.dtd')) and not file in files:
456 os.remove(path) 463 os.remove(path)
LEFTRIGHT
« build.py ('k') | 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