| Index: localeTools.py |
| diff --git a/localeTools.py b/localeTools.py |
| index b6554e0aa52461a7347c843a3b251d035ec34652..7d61932dd46384a6603ddc453a7f939be76f5016 100644 |
| --- a/localeTools.py |
| +++ b/localeTools.py |
| @@ -300,3 +300,37 @@ def getTranslations(localeConfig, projectName, key): |
| valid_extension = file.endswith('.json') |
| if os.path.isfile(path) and valid_extension and not file in files: |
| os.remove(path) |
| + |
| + |
| +def check_translations(localeConfig): |
| + path = localeConfig['base_path'] |
| + json_fld = path.rsplit('/', 1)[1] |
|
tlucas
2017/10/29 23:10:04
Use os.path.split() to split paths.
a) This will
erick
2017/10/31 04:30:02
I receive "AttributeError: 'tuple' object has no a
tlucas
2017/10/31 07:43:09
The error message pointed you to passing a tuple,
erick
2017/11/06 06:29:43
Done.
|
| + for locale in os.listdir('_locales/'): |
|
tlucas
2017/10/29 23:10:04
As pointed in out in the last comment '_locales' i
erick
2017/10/31 04:30:02
Done.
|
| + jsonpath = os.path.join('_locales/', locale, 'messages.json') |
| + |
| + if not os.path.exists(jsonpath): |
| + continue |
| + |
| + with codecs.open(jsonpath, 'rb', encoding='utf-8') as f: |
| + try: |
| + data = json.load(f) |
| + except ValueError, e: |
| + print >>sys.stderr, '%s -> File is not valid. %s' % e |
| + |
| + for key, value in data.iteritems(): |
| + variables = set() |
| + max_length = value.get('maxLength') |
| + length = len(value['message']) |
| + if max_length is not None and length > max_length or length > 160: |
| + print >>sys.stderr, ( |
| + '{} {} -> translation might be too long. More then 160 ' |
| + 'chars or maxLength exceeded').format(locale, key) |
| + |
| + for match in re.finditer(r'\$(\S+?)\$', value['message']): |
| + variables.add(match.group(1)) |
| + expected = set(value.get('placeholders', {}).iterkeys()) |
| + if variables != expected: |
| + print >>sys.stderr, ( |
|
tlucas
2017/10/29 23:10:04
nit: this is rather awkward to read.
maybe someth
erick
2017/10/31 04:30:02
Done.
|
| + '{} {}: Variables used are {} ' |
| + 'expected. Variables: {}').format( |
| + locale, key, variables, expected) |