Ticket #104: test_vars.py

File test_vars.py, 730 bytes (added by trev, on 05/07/2014 at 08:19:23 AM)

Chrome placeholder checking script

Line 
1#!/usr/bin/env python
2# coding: utf-8
3
4import sys
5import os
6import json
7import codecs
8import re
9
10for 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)