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(localeConfig): | |
306 base_path = localeConfig['base_path'] | |
307 for locale in os.listdir(base_path): | |
308 jsonpath = os.path.join(base_path, locale, 'messages.json') | |
309 | |
310 if not os.path.exists(jsonpath): | |
311 continue | |
312 | |
313 with codecs.open(jsonpath, 'rb', encoding='utf-8') as f: | |
314 try: | |
315 data = json.load(f) | |
316 except ValueError: | |
317 print >>sys.stderr, locale + ', messages.json is not valid.' | |
318 | |
319 for key, value in data.iteritems(): | |
320 variables = set() | |
321 max_length = value.get('maxLength') | |
322 length = len(value['message']) | |
323 if max_length is not None and length > max_length or length > 160: | |
324 print >>sys.stderr, ( | |
325 '{} {} -> translation might be too long. More then 160 ' | |
326 'chars or maxLength exceeded').format(locale, key) | |
327 | |
328 for match in re.finditer(r'\$(\S+?)\$', value['message']): | |
329 variables.add(match.group(1)) | |
330 expected = set(value.get('placeholders', {}).iterkeys()) | |
331 if variables != expected: | |
332 print >>sys.stderr, ( | |
333 '{} {}: Variables used are {} ' | |
334 'expected. Variables: {}' | |
335 ).format(locale, key, variables, expected) | |
tlucas
2017/11/06 15:48:12
py27 runtests: commands[2] | flake8
./localeTools.
erick
2017/11/07 08:18:44
Done.
| |
OLD | NEW |