Changeset 6349
- Timestamp:
- 09/15/07 22:17:48 (1 year ago)
- Files:
-
- django/trunk/django/bin/compile-messages.py (modified) (2 diffs)
- django/trunk/docs/i18n.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/bin/compile-messages.py
r4934 r6349 5 5 import sys 6 6 7 try: 8 set 9 except NameError: 10 from sets import Set as set # For Python 2.3 11 12 7 13 def compile_messages(locale=None): 8 basedir = None 14 basedirs = [os.path.join('conf', 'locale'), 'locale'] 15 if os.environ.get('DJANGO_SETTINGS_MODULE'): 16 from django.conf import settings 17 basedirs += settings.LOCALE_PATHS 9 18 10 if os.path.isdir(os.path.join('conf', 'locale')): 11 basedir = os.path.abspath(os.path.join('conf', 'locale')) 12 elif os.path.isdir('locale'): 13 basedir = os.path.abspath('locale') 14 else: 15 print "This script should be run from the Django SVN tree or your project or app tree." 19 # Gather existing directories. 20 basedirs = set(map(os.path.abspath, filter(os.path.isdir, basedirs))) 21 22 if not basedirs: 23 print "This script should be run from the Django SVN tree or your project or app tree, or with the settings module specified." 16 24 sys.exit(1) 17 25 18 if locale is not None: 19 basedir = os.path.join(basedir, locale, 'LC_MESSAGES') 26 for basedir in basedirs: 27 if locale: 28 basedir = os.path.join(basedir, locale, 'LC_MESSAGES') 29 compile_messages_in_dir(basedir) 20 30 31 def compile_messages_in_dir(basedir): 21 32 for dirpath, dirnames, filenames in os.walk(basedir): 22 33 for f in filenames: … … 41 52 parser.add_option('-l', '--locale', dest='locale', 42 53 help="The locale to process. Default is to process all.") 54 parser.add_option('--settings', 55 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.') 43 56 options, args = parser.parse_args() 44 57 if len(args): 45 58 parser.error("This program takes no arguments") 59 if options.settings: 60 os.environ['DJANGO_SETTINGS_MODULE'] = options.settings 46 61 compile_messages(options.locale) 47 62 django/trunk/docs/i18n.txt
r6343 r6349 670 670 where either the ``conf/locale`` (in case of the source tree) or the ``locale/`` 671 671 (in case of app messages or project messages) directory are located. And you 672 use the same ``compile-messages.py`` to produce the binary ``django.mo`` files that 673 are used by ``gettext``. 672 use the same ``compile-messages.py`` to produce the binary ``django.mo`` files 673 that are used by ``gettext``. 674 675 You can also run ``compile-message.py --settings=path.to.settings`` to make 676 the compiler process all the directories in your ``LOCALE_PATHS`` setting. 674 677 675 678 Application message files are a bit complicated to discover -- they need the
