Skip to content

Instantly share code, notes, and snippets.

@stephenmcd
Created June 18, 2012 11:33
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 stephenmcd/2947972 to your computer and use it in GitHub Desktop.
Save stephenmcd/2947972 to your computer and use it in GitHub Desktop.
A super-messy Django translation file parser.
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