summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2007-09-16 03:17:48 +0000
committerMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2007-09-16 03:17:48 +0000
commit8ccf2028c20054151b20248b9dc525bf78618fbc (patch)
tree7ac99e20b0a7ceafe4849126d9cd389d1268a71e /django
parentae75958820e344357ea716fcdbd5e56f06a00b24 (diff)
Fixed #3955 -- Added the ability to traverse LOCALE_PATHS when compiling PO files. Thanks, semenov.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@6349 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
-rwxr-xr-xdjango/bin/compile-messages.py33
1 files changed, 24 insertions, 9 deletions
diff --git a/django/bin/compile-messages.py b/django/bin/compile-messages.py
index 2e1e908bbf..2838cb8aa4 100755
--- a/django/bin/compile-messages.py
+++ b/django/bin/compile-messages.py
@@ -4,20 +4,31 @@ import optparse
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
+ 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 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."
+ 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__":