Django

Code

Changeset 6349

Show
Ignore:
Timestamp:
09/15/07 22:17:48 (1 year ago)
Author:
mtredinnick
Message:

Fixed #3955 -- Added the ability to traverse LOCALE_PATHS when compiling PO files. Thanks, semenov.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/bin/compile-messages.py

    r4934 r6349  
    55import sys 
    66 
     7try: 
     8    set 
     9except NameError: 
     10    from sets import Set as set     # For Python 2.3 
     11 
     12 
    713def 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 
    918 
    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." 
    1624        sys.exit(1) 
    1725 
    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) 
    2030 
     31def compile_messages_in_dir(basedir): 
    2132    for dirpath, dirnames, filenames in os.walk(basedir): 
    2233        for f in filenames: 
     
    4152    parser.add_option('-l', '--locale', dest='locale', 
    4253            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.') 
    4356    options, args = parser.parse_args() 
    4457    if len(args): 
    4558        parser.error("This program takes no arguments") 
     59    if options.settings: 
     60        os.environ['DJANGO_SETTINGS_MODULE'] = options.settings 
    4661    compile_messages(options.locale) 
    4762 
  • django/trunk/docs/i18n.txt

    r6343 r6349  
    670670where either the ``conf/locale`` (in case of the source tree) or the ``locale/`` 
    671671(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``. 
     672use the same ``compile-messages.py`` to produce the binary ``django.mo`` files 
     673that are used by ``gettext``. 
     674 
     675You can also run ``compile-message.py --settings=path.to.settings`` to make 
     676the compiler process all the directories in your ``LOCALE_PATHS`` setting. 
    674677 
    675678Application message files are a bit complicated to discover -- they need the