Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

…ing PO files. Thanks, semenov.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@6349 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 8ccf2028c20054151b20248b9dc525bf78618fbc 1 parent ae75958
@malcolmt malcolmt authored
Showing with 30 additions and 12 deletions.
  1. +25 −10 django/bin/compile-messages.py
  2. +5 −2 docs/i18n.txt
View
35 django/bin/compile-messages.py
@@ -4,20 +4,31 @@
import os
import sys
+try:
+ 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."
sys.exit(1)
- 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
compile_messages(options.locale)
if __name__ == "__main__":
View
7 docs/i18n.txt
@@ -669,8 +669,11 @@ To create message files, you use the same ``make-messages.py`` 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 ``compile-messages.py`` to produce the binary ``django.mo`` files that
-are used by ``gettext``.
+use the same ``compile-messages.py`` to produce the binary ``django.mo`` files
+that are used by ``gettext``.
+
+You can also run ``compile-message.py --settings=path.to.settings`` 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
Please sign in to comment.
Something went wrong with that request. Please try again.