Skip to content

Instantly share code, notes, and snippets.

@juliandescottes
Last active September 1, 2016 08:54
Show Gist options
  • Save juliandescottes/4c2c2145a210c106c3ec329b2dfdc7b0 to your computer and use it in GitHub Desktop.
Save juliandescottes/4c2c2145a210c106c3ec329b2dfdc7b0 to your computer and use it in GitHub Desktop.
import argparse, fileinput, glob, os, re
def get_keys_from_file(path):
if not os.path.exists(path):
print 'path: [%s] is invalid' % path
f = open(path, 'r')
lines = f.readlines()
f.close()
keys = []
for i, line in enumerate(lines):
m = re.search('^([a-zA-Z0-9.]+)\s*=', line)
if m and m.group(1):
subkeys = m.group(1).split('.')
keys = keys + subkeys
return keys;
def get_js_files(path):
js_files = []
for root, dirs, files in os.walk(path):
for file in files:
if file.endswith('.js') or file.endswith('.jsm'):
js_files.append(os.path.join(root, file))
return js_files
def find_key_in_files(key, files):
found = False
for file in files:
with open(file) as f:
contents = f.read()
if key in contents:
found = True
return found
files = glob.glob('client/locales/en-US/*.properties')
count = 0;
total = 0;
js_files = get_js_files('client')
for property_file in files:
keys = get_keys_from_file(property_file)
# print 'got {0} keys from {1}'.format(len(keys), property_file)
for key in keys:
total = total + 1
found = find_key_in_files(key, js_files)
if not found:
count = count + 1
print '{0} : {1}'.format(property_file, key)
print 'Processed {0} keys'.format(total)
print 'Missing {0} keys'.format(count)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment