Ticket #3955: compile-messages-use-settings-module.diff
File compile-messages-use-settings-module.diff, 3.0 KB (added by , 17 years ago) |
---|
-
django/bin/compile-messages.py
4 4 import os 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 9 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." 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 18 19 # leave unique existent 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 is not None: 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: 23 34 if f.endswith('.po'): … … 40 51 parser = optparse.OptionParser() 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 48 63 if __name__ == "__main__": -
docs/i18n.txt
708 708 where either the ``conf/locale`` (in case of the source tree) or the ``locale/`` 709 709 (in case of app messages or project messages) directory are located. And you 710 710 use the same ``compile-messages.py`` to produce the binary ``django.mo`` files that 711 are used by ``gettext``. 711 are used by ``gettext``. You can also run ``compile-message.py 712 --settings=path.to.settings`` to make the compiler process all your ``LOCALE_PATHS``. 712 713 713 714 Application message files are a bit complicated to discover -- they need the 714 715 ``LocaleMiddleware``. If you don't use the middleware, only the Django message