Skip to content

Instantly share code, notes, and snippets.

@paltman
Forked from rizumu/translate.py
Created August 31, 2011 22:52
Show Gist options
  • Select an option

  • Save paltman/1184967 to your computer and use it in GitHub Desktop.

Select an option

Save paltman/1184967 to your computer and use it in GitHub Desktop.

Revisions

  1. Thomas Schreiber created this gist Aug 31, 2011.
    30 changes: 30 additions & 0 deletions translate.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    """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)