Created
June 18, 2012 11:33
-
-
Save stephenmcd/2947972 to your computer and use it in GitHub Desktop.
A super-messy Django translation file parser.
This file contains hidden or 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
import os | |
translators = [] | |
languages = [] | |
for root, dirs, files in os.walk("mezz_current/mezzanine"): | |
if root.endswith("locale"): | |
languages.extend(dirs) | |
for name in files: | |
if name == "django.po": | |
with open(os.path.join(root, name)) as f: | |
lines = f.read() | |
try: | |
ts = lines.split("Translators")[1].split( | |
"msgid")[0].split("\n") | |
except: | |
pass | |
else: | |
translators.extend([l.strip("# ").split(" <")[0] | |
for l in ts if l.startswith("#")]) | |
others = [l.split(": ")[1].split(" <")[0] | |
for l in lines.split("\n") | |
if l.startswith("\"Last-Translator: ") or | |
l.startswith("\"Language-Team: ")] | |
if others[0] != "FULL NAME" and "http" not in others[-1]: | |
translators.extend(others) | |
translators = [t.split(",")[0].strip() for t in translators | |
if not t.startswith("<") and t != "LANGUAGE" and | |
t.strip() and " " in t.strip()] | |
for t in set(translators): | |
print t | |
for l in set(languages): | |
print l |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment