Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: localeTools.py

Issue 29587910: Issue 104 - added checktranslations function
Patch Set: Created Oct. 24, 2017, 11:36 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« build.py ('K') | « build.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: localeTools.py
diff --git a/localeTools.py b/localeTools.py
index b6554e0aa52461a7347c843a3b251d035ec34652..43d3642b6054886c345ce0721612c89b3903fd35 100644
--- a/localeTools.py
+++ b/localeTools.py
@@ -300,3 +300,36 @@ 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(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.
+ 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.
+ 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
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.
+
+ for key, value in data.iteritems():
+ variables = set()
+ max_length = value.get('maxLength')
+ msg_length = len(value['message'])
+ 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.
+ 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.
+ 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.
+ 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.
+ 'translation might be too long. More then', \
+ '160 chars or maxLength exceeded'
+
+ for match in re.finditer(r'\$(\S+?)\$', value['message']):
+ variables.add(match.group(1))
+ 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?
+ if variables != expected:
+ print >>sys.stderr, '%s %s: Variables' % (locale, key), \
+ 'used are %s, expected.' % variables, \
+ 'Variables: %s' % expected
« build.py ('K') | « build.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld