1 | #!/usr/bin/env python |
---|
2 | # coding: utf-8 |
---|
3 | |
---|
4 | import sys |
---|
5 | import os |
---|
6 | import json |
---|
7 | import codecs |
---|
8 | import re |
---|
9 | |
---|
10 | for locale in os.listdir("_locales"): |
---|
11 | if locale.startswith("."): |
---|
12 | continue |
---|
13 | jsonpath = os.path.join("_locales", locale, "messages.json") |
---|
14 | if not os.path.exists(jsonpath): |
---|
15 | continue |
---|
16 | |
---|
17 | with codecs.open(jsonpath, 'rb', encoding='utf-8') as f: |
---|
18 | data = json.load(f) |
---|
19 | |
---|
20 | for key, value in data.iteritems(): |
---|
21 | variables = set() |
---|
22 | for match in re.finditer(r'\$(\S+?)\$', value['message']): |
---|
23 | variables.add(match.group(1)) |
---|
24 | expected = set(value.get("placeholders", {}).iterkeys()) |
---|
25 | if variables != expected: |
---|
26 | print >>sys.stderr, '%s %s: Variables used are %s, expected %s' % (locale, key, variables, expected) |
---|