Skip to content

Instantly share code, notes, and snippets.

@rizumu
Created August 31, 2011 22:49
Show Gist options
  • Save rizumu/1184958 to your computer and use it in GitHub Desktop.
Save rizumu/1184958 to your computer and use it in GitHub Desktop.
translate
"""A management command for extracting translation messages for the whole project."""
import glob
import os
from django.conf import settings
from django.core.management.base import NoArgsCommand
class Command(NoArgsCommand):
help = "Make and compile all translation messages for the whole project."
def handle_noargs(self, **options):
root = settings.PROJECT_ROOT
manage_py = os.path.join(root, "manage.py")
makemessages = "%s makemessages -v0 --all --extension='.txt,.html,.json'" % manage_py
compilemessages = "%s compilemessages" % manage_py
# top level messages
self.run(makemessages + " --ignore='apps/*'")
self.run(compilemessages)
# application-specific messages
for app_dir in glob.glob(os.path.join(root, "apps", "*")):
if os.path.isdir(os.path.join(app_dir, "locale")):
os.chdir(app_dir)
self.run(makemessages)
self.run(compilemessages)
def run(self, cmd):
print cmd
os.system(cmd)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment