Created
August 25, 2014 14:42
-
-
Save pquentin/a95b7612e9e05716b23b to your computer and use it in GitHub Desktop.
Compare codefirefox localization file with __ calls in the code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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