Browse files

Fixed #3955 -- Added the ability to traverse LOCALE_PATHS when compi…

…ling PO files. Thanks, semenov.

git-svn-id: bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
malcolmt committed Sep 16, 2007
1 parent ae75958 commit 8ccf2028c20054151b20248b9dc525bf78618fbc
Showing with 30 additions and 12 deletions.
  1. +25 −10 django/bin/
  2. +5 −2 docs/i18n.txt
@@ -4,20 +4,31 @@
import os
import sys
+ set
+except NameError:
+ from sets import Set as set # For Python 2.3
def compile_messages(locale=None):
- basedir = None
- if os.path.isdir(os.path.join('conf', 'locale')):
- basedir = os.path.abspath(os.path.join('conf', 'locale'))
- elif os.path.isdir('locale'):
- basedir = os.path.abspath('locale')
- else:
- print "This script should be run from the Django SVN tree or your project or app tree."
+ basedirs = [os.path.join('conf', 'locale'), 'locale']
+ if os.environ.get('DJANGO_SETTINGS_MODULE'):
+ from django.conf import settings
+ basedirs += settings.LOCALE_PATHS
+ # Gather existing directories.
+ basedirs = set(map(os.path.abspath, filter(os.path.isdir, basedirs)))
+ if not basedirs:
+ print "This script should be run from the Django SVN tree or your project or app tree, or with the settings module specified."
- if locale is not None:
- basedir = os.path.join(basedir, locale, 'LC_MESSAGES')
+ for basedir in basedirs:
+ if locale:
+ basedir = os.path.join(basedir, locale, 'LC_MESSAGES')
+ compile_messages_in_dir(basedir)
+def compile_messages_in_dir(basedir):
for dirpath, dirnames, filenames in os.walk(basedir):
for f in filenames:
if f.endswith('.po'):
@@ -40,9 +51,13 @@ def main():
parser = optparse.OptionParser()
parser.add_option('-l', '--locale', dest='locale',
help="The locale to process. Default is to process all.")
+ parser.add_option('--settings',
+ help='Python path to settings module, e.g. "myproject.settings". If provided, all LOCALE_PATHS will be processed. If this isn\'t provided, the DJANGO_SETTINGS_MODULE environment variable will be checked as well.')
options, args = parser.parse_args()
if len(args):
parser.error("This program takes no arguments")
+ if options.settings:
+ os.environ['DJANGO_SETTINGS_MODULE'] = options.settings
if __name__ == "__main__":
@@ -669,8 +669,11 @@ To create message files, you use the same ```` tool as with the
Django message files. You only need to be in the right place -- in the directory
where either the ``conf/locale`` (in case of the source tree) or the ``locale/``
(in case of app messages or project messages) directory are located. And you
-use the same ```` to produce the binary ```` files that
-are used by ``gettext``.
+use the same ```` to produce the binary ```` files
+that are used by ``gettext``.
+You can also run ```` to make
+the compiler process all the directories in your ``LOCALE_PATHS`` setting.
Application message files are a bit complicated to discover -- they need the
``LocaleMiddleware``. If you don't use the middleware, only the Django message

0 comments on commit 8ccf202

Please sign in to comment.