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
This commit is contained in:
parent
ae75958820
commit
8ccf2028c2
|
@ -4,20 +4,31 @@ import optparse
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
def compile_messages(locale=None):
|
try:
|
||||||
basedir = None
|
set
|
||||||
|
except NameError:
|
||||||
|
from sets import Set as set # For Python 2.3
|
||||||
|
|
||||||
if os.path.isdir(os.path.join('conf', 'locale')):
|
|
||||||
basedir = os.path.abspath(os.path.join('conf', 'locale'))
|
def compile_messages(locale=None):
|
||||||
elif os.path.isdir('locale'):
|
basedirs = [os.path.join('conf', 'locale'), 'locale']
|
||||||
basedir = os.path.abspath('locale')
|
if os.environ.get('DJANGO_SETTINGS_MODULE'):
|
||||||
else:
|
from django.conf import settings
|
||||||
print "This script should be run from the Django SVN tree or your project or app tree."
|
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)
|
sys.exit(1)
|
||||||
|
|
||||||
if locale is not None:
|
for basedir in basedirs:
|
||||||
basedir = os.path.join(basedir, locale, 'LC_MESSAGES')
|
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 dirpath, dirnames, filenames in os.walk(basedir):
|
||||||
for f in filenames:
|
for f in filenames:
|
||||||
if f.endswith('.po'):
|
if f.endswith('.po'):
|
||||||
|
@ -40,9 +51,13 @@ def main():
|
||||||
parser = optparse.OptionParser()
|
parser = optparse.OptionParser()
|
||||||
parser.add_option('-l', '--locale', dest='locale',
|
parser.add_option('-l', '--locale', dest='locale',
|
||||||
help="The locale to process. Default is to process all.")
|
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()
|
options, args = parser.parse_args()
|
||||||
if len(args):
|
if len(args):
|
||||||
parser.error("This program takes no arguments")
|
parser.error("This program takes no arguments")
|
||||||
|
if options.settings:
|
||||||
|
os.environ['DJANGO_SETTINGS_MODULE'] = options.settings
|
||||||
compile_messages(options.locale)
|
compile_messages(options.locale)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
@ -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
|
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/``
|
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
|
(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
|
use the same ``compile-messages.py`` to produce the binary ``django.mo`` files
|
||||||
are used by ``gettext``.
|
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
|
Application message files are a bit complicated to discover -- they need the
|
||||||
``LocaleMiddleware``. If you don't use the middleware, only the Django message
|
``LocaleMiddleware``. If you don't use the middleware, only the Django message
|
||||||
|
|
Loading…
Reference in New Issue