Left: | ||
Right: |
OLD | NEW |
---|---|
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 urlparse | 10 import urlparse |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
293 # Remove any extra files | 293 # Remove any extra files |
294 for dir, files in dirs.iteritems(): | 294 for dir, files in dirs.iteritems(): |
295 baseDir = os.path.join(localeConfig['base_path'], dir) | 295 baseDir = os.path.join(localeConfig['base_path'], dir) |
296 if not os.path.exists(baseDir): | 296 if not os.path.exists(baseDir): |
297 continue | 297 continue |
298 for file in os.listdir(baseDir): | 298 for file in os.listdir(baseDir): |
299 path = os.path.join(baseDir, file) | 299 path = os.path.join(baseDir, file) |
300 valid_extension = file.endswith('.json') | 300 valid_extension = file.endswith('.json') |
301 if os.path.isfile(path) and valid_extension and not file in files: | 301 if os.path.isfile(path) and valid_extension and not file in files: |
302 os.remove(path) | 302 os.remove(path) |
303 | |
304 | |
305 def check_translations(dir): | |
tlucas
2017/10/25 15:09:23
The parameter is not used anywhere in this functio
erick
2017/10/29 03:45:56
Acknowledged.
erick
2017/10/31 04:30:00
Done.
erick
2017/10/31 04:30:01
Done.
| |
306 for locale in os.listdir('_locales/'): | |
tlucas
2017/10/25 15:09:23
"_locales" is only valid for adblockpluschrome.
i
erick
2017/10/29 03:45:55
Acknowledged.
erick
2017/10/31 04:29:59
Done.
| |
307 jsonpath = os.path.join('_locales/', locale, 'messages.json') | |
308 | |
309 if not os.path.exists(jsonpath): | |
310 continue | |
311 | |
312 with codecs.open(jsonpath, 'rb', encoding='utf-8') as f: | |
313 try: | |
314 data = json.load(f) | |
315 except ValueError, e: | |
316 print >>sys.stderr, '%s -> File is not valid. %s' % e | |
tlucas
2017/10/25 15:09:23
nit: https://adblockplus.org/en/coding-style (sect
erick
2017/10/29 03:45:55
Acknowledged.
tlucas
2017/10/29 23:10:03
This is NOT done.
erick
2017/10/31 04:30:01
Done.
| |
317 | |
318 for key, value in data.iteritems(): | |
319 variables = set() | |
320 max_length = value.get('maxLength') | |
321 msg_length = len(value['message']) | |
322 if (max_length is not None | |
tlucas
2017/10/25 15:09:23
nit: I still suggest using a shorter variable name
erick
2017/10/29 03:45:56
Acknowledged.
erick
2017/10/31 04:30:00
Done.
erick
2017/10/31 04:30:01
Done.
| |
323 and msg_length > max_length | |
tlucas
2017/10/25 15:09:23
Tox fails on this line:
./localeTools.py:323:17:
erick
2017/10/29 03:45:55
Acknowledged.
erick
2017/10/31 04:29:59
Done.
erick
2017/10/31 04:29:59
Done.
| |
324 or msg_length > 160): | |
tlucas
2017/10/25 15:09:23
Tox fails on this line:
./localeTools.py:324:17:
erick
2017/10/29 03:45:55
Acknowledged.
erick
2017/10/31 04:30:00
Done.
erick
2017/10/31 04:30:00
Done.
| |
325 print >>sys.stderr, '%s %s ->' % (locale, key), \ | |
tlucas
2017/10/25 15:09:23
https://adblockplus.org/en/coding-style (section "
erick
2017/10/29 03:45:55
Acknowledged.
erick
2017/10/31 04:30:00
Done.
erick
2017/10/31 04:30:01
Done.
| |
326 'translation might be too long. More then', \ | |
327 '160 chars or maxLength exceeded' | |
328 | |
329 for match in re.finditer(r'\$(\S+?)\$', value['message']): | |
330 variables.add(match.group(1)) | |
331 expected = set(value.get('placeholders', {}).iterkeys()) | |
tlucas
2017/10/25 15:09:23
The above 3 lines seem rather complicated. Maybe s
erick
2017/10/29 03:45:55
Is a possible way to check for an empty set() then
tlucas
2017/10/29 23:10:03
Why would you want to potentially double cpu load?
| |
332 if variables != expected: | |
333 print >>sys.stderr, '%s %s: Variables' % (locale, key), \ | |
334 'used are %s, expected.' % variables, \ | |
335 'Variables: %s' % expected | |
OLD | NEW |