Skip to content

Instantly share code, notes, and snippets.

@pquentin
Created August 25, 2014 14:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pquentin/a95b7612e9e05716b23b to your computer and use it in GitHub Desktop.
Save pquentin/a95b7612e9e05716b23b to your computer and use it in GitHub Desktop.
Compare codefirefox localization file with __ calls in the code
#!/usr/bin/env python3
from glob import glob
import re
import json
def get_code_strings():
for filename in glob("views/*.jade"):
content = open(filename).read()
for s in re.findall(r'__\("[^"]+', content):
yield s[4:]
for s in re.findall(r"__\('[^']+", content):
yield s[4:]
def get_video_strings(vf):
videos_json = json.load(vf)
videos_text = set()
for section in videos_json:
videos_text.add(section['title'])
for v in section['videos']:
videos_text.add(v['title'])
videos_text.add(v['description'])
if 'assertions' in v:
for assertion in v['assertions']:
videos_text.add(assertion['title'])
videos_text |= set(assertion['hints'])
return videos_text
def get_json_strings(cf):
return set(json.loads(cf.read()).keys())
template_keys = set(get_code_strings())
video_keys = get_video_strings(open('data/videos.json'))
json_keys = get_json_strings(open('locales/en.js'))
live_keys = template_keys | video_keys
localized_keys = json_keys
print("Extra strings:", sorted(localized_keys - live_keys))
print("Missing strings:", sorted(live_keys - localized_keys))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment