| LEFT | RIGHT |
| 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 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 if not os.path.exists(jsonpath): | 310 if not os.path.exists(jsonpath): |
| 311 continue | 311 continue |
| 312 | 312 |
| 313 with codecs.open(jsonpath, 'rb', encoding='utf-8') as f: | 313 with codecs.open(jsonpath, 'rb', encoding='utf-8') as f: |
| 314 try: | 314 try: |
| 315 data = json.load(f) | 315 data = json.load(f) |
| 316 for key, value in data.iteritems(): | 316 for key, value in data.iteritems(): |
| 317 variables = set() | 317 variables = set() |
| 318 max_length = value.get('maxLength') | 318 max_length = value.get('maxLength') |
| 319 length = len(value['message']) | 319 length = len(value['message']) |
| 320 if (max_length is not None | 320 if (max_length is not None and |
| 321 and length > max_length or length > 160): | 321 length > max_length or length > 160): |
| 322 print >>sys.stderr, ( | 322 print >>sys.stderr, ( |
| 323 '{} {} -> translation might be too long.' | 323 '{} {} -> translation might be too long.' |
| 324 'More then 160 chars or maxLength exceeded' | 324 'More then 160 chars or maxLength exceeded' |
| 325 ).format(locale, key) | 325 ).format(locale, key) |
| 326 | 326 |
| 327 for match in re.finditer(r'\$(\S+?)\$', value['message']): | 327 for match in re.finditer(r'\$(\S+?)\$', value['message']): |
| 328 variables.add(match.group(1)) | 328 variables.add(match.group(1)) |
| 329 expected = set(value.get('placeholders', {}).iterkeys()) | 329 expected = set(value.get('placeholders', {}).iterkeys()) |
| 330 if variables != expected: | 330 if variables != expected: |
| 331 print >>sys.stderr, ( | 331 print >>sys.stderr, ( |
| 332 '{} {}: Variables used are {} ' | 332 '{} {}: Variables used are {} ' |
| 333 'expected. Variables: {}' | 333 'expected. Variables: {}' |
| 334 ).format(locale, key, variables, expected) | 334 ).format(locale, key, variables, expected) |
| 335 except ValueError: | 335 except ValueError: |
| 336 print >>sys.stderr, locale + ', messages.json is not valid.' | 336 print >>sys.stderr, locale + ', messages.json is not valid.' |
| LEFT | RIGHT |