Ticket #5522: django-admin.2.diff

File django-admin.2.diff, 36.5 KB (added by jezdez, 7 years ago)

second patch to move utilities in django/bin to django.core.management

  • django/bin/compile-messages.py

    diff -r 8cd5ecf7b694 django/bin/compile-messages.py
    a b  
    11#!/usr/bin/env python
    22
    33import optparse
    4 import os
    5 import sys
    6 
    7 try:
    8     set
    9 except NameError:
    10     from sets import Set as set     # For Python 2.3
    11 
    12 
    13 def compile_messages(locale=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
    18 
    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."
    24         sys.exit(1)
    25 
    26     for basedir in basedirs:
    27         if locale:
    28             basedir = os.path.join(basedir, locale, 'LC_MESSAGES')
    29         compile_messages_in_dir(basedir)
    30 
    31 def compile_messages_in_dir(basedir):
    32     for dirpath, dirnames, filenames in os.walk(basedir):
    33         for f in filenames:
    34             if f.endswith('.po'):
    35                 sys.stderr.write('processing file %s in %s\n' % (f, dirpath))
    36                 pf = os.path.splitext(os.path.join(dirpath, f))[0]
    37                 # Store the names of the .mo and .po files in an environment
    38                 # variable, rather than doing a string replacement into the
    39                 # command, so that we can take advantage of shell quoting, to
    40                 # quote any malicious characters/escaping.
    41                 # See http://cyberelk.net/tim/articles/cmdline/ar01s02.html
    42                 os.environ['djangocompilemo'] = pf + '.mo'
    43                 os.environ['djangocompilepo'] = pf + '.po'
    44                 if sys.platform == 'win32': # Different shell-variable syntax
    45                     cmd = 'msgfmt --check-format -o "%djangocompilemo%" "%djangocompilepo%"'
    46                 else:
    47                     cmd = 'msgfmt --check-format -o "$djangocompilemo" "$djangocompilepo"'
    48                 os.system(cmd)
     4from django.core import management
    495
    506def main():
    517    parser = optparse.OptionParser()
    def main(): 
    5612    options, args = parser.parse_args()
    5713    if len(args):
    5814        parser.error("This program takes no arguments")
    59     if options.settings:
    60         os.environ['DJANGO_SETTINGS_MODULE'] = options.settings
    61     compile_messages(options.locale)
     15    if not options.settings:
     16        options.settings = None
     17    management.call_command('messagescompile', locale=options.locale, settings=options.settings)
    6218
    6319if __name__ == "__main__":
    6420    main()
  • django/bin/daily_cleanup.py

    diff -r 8cd5ecf7b694 django/bin/daily_cleanup.py
    a b sessions at the moment). 
    77sessions at the moment).
    88"""
    99
    10 import datetime
    11 from django.db import transaction
    12 from django.contrib.sessions.models import Session
    13 
    14 def clean_up():
    15     """Clean up expired sessions."""
    16     Session.objects.filter(expire_date__lt=datetime.datetime.now()).delete()
    17     transaction.commit_unless_managed()
     10from django.core import management
    1811
    1912if __name__ == "__main__":
    20     clean_up()
     13    management.call_command('cleanup')
  • django/bin/make-messages.py

    diff -r 8cd5ecf7b694 django/bin/make-messages.py
    a b  
    11#!/usr/bin/env python
    22
    3 # Need to ensure that the i18n framework is enabled
    4 from django.conf import settings
    5 settings.configure(USE_I18N = True)
    6 
    7 from django.utils.translation import templatize
    8 import re
    93import os
    104import sys
    115import getopt
    12 from itertools import dropwhile
     6import optparse
     7from django.core import management
    138
    14 pythonize_re = re.compile(r'\n\s*//')
     9def main():
     10    parser = optparse.OptionParser()
     11    parser.add_option('-l', '--locale', dest='locale',
     12        help='Creates or updates the message files only for the given locale (e.g. pt_BR).')
     13    parser.add_option('-d', '--domain', dest='domain', default='django',
     14        help='The domain of the message files (default: "django").')
     15    parser.add_option('-v', '--verbose', action='store_true', dest='verbose', default=False,
     16        help='Verbosity output')
     17    parser.add_option('-a', '--all', action='store_true', dest='all', default=False,
     18        help='Reexamines all source code and templates for new translation strings and updates all message files for all available languages.')
    1519
    16 def make_messages():
    17     localedir = None
    18 
    19     if os.path.isdir(os.path.join('conf', 'locale')):
    20         localedir = os.path.abspath(os.path.join('conf', 'locale'))
    21     elif os.path.isdir('locale'):
    22         localedir = os.path.abspath('locale')
     20    options, args = parser.parse_args()
     21    if len(args):
     22        parser.error("This program takes no arguments")
     23    if options.verbose:
     24        verbosity = 2
    2325    else:
    24         print "This script should be run from the django svn tree or your project or app tree."
    25         print "If you did indeed run it from the svn checkout or your project or application,"
    26         print "maybe you are just missing the conf/locale (in the django tree) or locale (for project"
    27         print "and application) directory?"
    28         print "make-messages.py doesn't create it automatically, you have to create it by hand if"
    29         print "you want to enable i18n for your project or application."
    30         sys.exit(1)
    31 
    32     (opts, args) = getopt.getopt(sys.argv[1:], 'l:d:va')
    33 
    34     lang = None
    35     domain = 'django'
    36     verbose = False
    37     all = False
    38 
    39     for o, v in opts:
    40         if o == '-l':
    41             lang = v
    42         elif o == '-d':
    43             domain = v
    44         elif o == '-v':
    45             verbose = True
    46         elif o == '-a':
    47             all = True
    48 
    49     if domain not in ('django', 'djangojs'):
    50         print "currently make-messages.py only supports domains 'django' and 'djangojs'"
    51         sys.exit(1)
    52     if (lang is None and not all) or domain is None:
    53         print "usage: make-messages.py -l <language>"
    54         print "   or: make-messages.py -a"
    55         sys.exit(1)
    56 
    57     languages = []
    58 
    59     if lang is not None:
    60         languages.append(lang)
    61     elif all:
    62         languages = [el for el in os.listdir(localedir) if not el.startswith('.')]
    63 
    64     for lang in languages:
    65 
    66         print "processing language", lang
    67         basedir = os.path.join(localedir, lang, 'LC_MESSAGES')
    68         if not os.path.isdir(basedir):
    69             os.makedirs(basedir)
    70 
    71         pofile = os.path.join(basedir, '%s.po' % domain)
    72         potfile = os.path.join(basedir, '%s.pot' % domain)
    73 
    74         if os.path.exists(potfile):
    75             os.unlink(potfile)
    76 
    77         all_files = []
    78         for (dirpath, dirnames, filenames) in os.walk("."):
    79             all_files.extend([(dirpath, f) for f in filenames])
    80         all_files.sort()
    81         for dirpath, file in all_files:
    82             if domain == 'djangojs' and file.endswith('.js'):
    83                 if verbose: sys.stdout.write('processing file %s in %s\n' % (file, dirpath))
    84                 src = open(os.path.join(dirpath, file), "rb").read()
    85                 src = pythonize_re.sub('\n#', src)
    86                 open(os.path.join(dirpath, '%s.py' % file), "wb").write(src)
    87                 thefile = '%s.py' % file
    88                 cmd = 'xgettext %s -d %s -L Perl --keyword=gettext_noop --keyword=gettext_lazy --keyword=ngettext_lazy:1,2 --from-code UTF-8 -o - "%s"' % (
    89                     os.path.exists(potfile) and '--omit-header' or '', domain, os.path.join(dirpath, thefile))
    90                 (stdin, stdout, stderr) = os.popen3(cmd, 't')
    91                 msgs = stdout.read()
    92                 errors = stderr.read()
    93                 if errors:
    94                     print "errors happened while running xgettext on %s" % file
    95                     print errors
    96                     sys.exit(8)
    97                 old = '#: '+os.path.join(dirpath, thefile)[2:]
    98                 new = '#: '+os.path.join(dirpath, file)[2:]
    99                 msgs = msgs.replace(old, new)
    100                 if msgs:
    101                     open(potfile, 'ab').write(msgs)
    102                 os.unlink(os.path.join(dirpath, thefile))
    103             elif domain == 'django' and (file.endswith('.py') or file.endswith('.html')):
    104                 thefile = file
    105                 if file.endswith('.html'):
    106                     src = open(os.path.join(dirpath, file), "rb").read()
    107                     thefile = '%s.py' % file
    108                     open(os.path.join(dirpath, thefile), "wb").write(templatize(src))
    109                 if verbose:
    110                     sys.stdout.write('processing file %s in %s\n' % (file, dirpath))
    111                 cmd = 'xgettext -d %s -L Python --keyword=gettext_noop --keyword=gettext_lazy --keyword=ngettext_lazy:1,2 --keyword=ugettext_noop --keyword=ugettext_lazy --keyword=ungettext_lazy:1,2 --from-code UTF-8 -o - "%s"' % (
    112                     domain, os.path.join(dirpath, thefile))
    113                 (stdin, stdout, stderr) = os.popen3(cmd, 't')
    114                 msgs = stdout.read()
    115                 errors = stderr.read()
    116                 if errors:
    117                     print "errors happened while running xgettext on %s" % file
    118                     print errors
    119                     sys.exit(8)
    120                 if thefile != file:
    121                     old = '#: '+os.path.join(dirpath, thefile)[2:]
    122                     new = '#: '+os.path.join(dirpath, file)[2:]
    123                     msgs = msgs.replace(old, new)
    124                 if os.path.exists(potfile):
    125                     # Strip the header
    126                     msgs = '\n'.join(dropwhile(len, msgs.split('\n')))
    127                 else:
    128                     msgs = msgs.replace('charset=CHARSET', 'charset=UTF-8')
    129                 if msgs:
    130                     open(potfile, 'ab').write(msgs)
    131                 if thefile != file:
    132                     os.unlink(os.path.join(dirpath, thefile))
    133 
    134         if os.path.exists(potfile):
    135             (stdin, stdout, stderr) = os.popen3('msguniq --to-code=utf-8 "%s"' % potfile, 'b')
    136             msgs = stdout.read()
    137             errors = stderr.read()
    138             if errors:
    139                 print "errors happened while running msguniq"
    140                 print errors
    141                 sys.exit(8)
    142             open(potfile, 'w').write(msgs)
    143             if os.path.exists(pofile):
    144                 (stdin, stdout, stderr) = os.popen3('msgmerge -q "%s" "%s"' % (pofile, potfile), 'b')
    145                 msgs = stdout.read()
    146                 errors = stderr.read()
    147                 if errors:
    148                     print "errors happened while running msgmerge"
    149                     print errors
    150                     sys.exit(8)
    151             open(pofile, 'wb').write(msgs)
    152             os.unlink(potfile)
     26        verbosity = 1
     27   
     28    management.call_command('messagesmake', locale=options.locale,
     29        domain=options.domain, verbosity=verbosity, all=options.all)
    15330
    15431if __name__ == "__main__":
    155     make_messages()
     32    main()
  • django/core/management/base.py

    diff -r 8cd5ecf7b694 django/core/management/base.py
    a b def copy_helper(style, app_or_project, n 
    220220            except OSError:
    221221                sys.stderr.write(style.NOTICE("Notice: Couldn't set permission bits on %s. You're probably using an uncommon filesystem setup. No problem.\n" % path_new))
    222222
     223def get_locale_dir():
     224    "Returns the locale directory from the Django SVN tree or an application/project"
     225    if os.path.isdir(os.path.join('conf', 'locale')):
     226        basedir = os.path.abspath(os.path.join('conf', 'locale'))
     227    elif os.path.isdir('locale'):
     228        basedir = os.path.abspath('locale')
     229    else:
     230        raise CommandError("This script should be run from the Django SVN tree or your project or app tree. If you did indeed run it from the SVN checkout or your project or application, maybe you are just missing the conf/locale (in the django tree) or locale (for project and application) directory? It is not created automatically, you have to create it by hand if you want to enable i18n for your project or application.")
     231    return basedir
     232
     233
    223234def _make_writeable(filename):
    224235    "Makes sure that the file is writeable. Useful if our source is read-only."
    225236    import stat
  • new file django/core/management/commands/cleanup.py

    diff -r 8cd5ecf7b694 django/core/management/commands/cleanup.py
    - +  
     1import datetime
     2from django.core.management.base import NoArgsCommand
     3
     4class Command(NoArgsCommand):
     5    help = "Can be run as a cronjob or directly to clean out old data from the database (only expired sessions at the moment)."
     6
     7    def handle_noargs(self, **options):
     8        from django.db import transaction
     9        from django.contrib.sessions.models import Session
     10        Session.objects.filter(expire_date__lt=datetime.datetime.now()).delete()
     11        transaction.commit_unless_managed()
  • new file django/core/management/commands/messagescompile.py

    diff -r 8cd5ecf7b694 django/core/management/commands/messagescompile.py
    - +  
     1import os
     2import sys
     3from optparse import make_option
     4from django.core.management.base import BaseCommand, CommandError, get_locale_dir
     5from django.core.management.color import no_style
     6
     7try:
     8    set
     9except NameError:
     10    from sets import Set as set     # For Python 2.3
     11
     12class Command(BaseCommand):
     13    option_list = BaseCommand.option_list + (
     14        make_option('--locale', '-l', dest='locale',
     15            help='The locale to process. Default is to process all.'),
     16    )
     17    help = 'Compiles .po files to .mo files for use with builtin gettext support.'
     18
     19    requires_model_validation = False
     20    can_import_settings = False
     21
     22    def handle(self, **options):
     23        basedirs = (os.path.join('conf', 'locale'), 'locale')
     24        if os.environ.get('DJANGO_SETTINGS_MODULE'):
     25            from django.conf import settings
     26            basedirs += settings.LOCALE_PATHS
     27
     28        # Gather existing directories.
     29        basedirs = set(map(os.path.abspath, filter(os.path.isdir, basedirs)))
     30       
     31        if not basedirs:
     32            raise CommandError("This script should be run from the Django SVN tree or your project or app tree, or with the settings module specified.")
     33
     34        locale = options.get('locale', None)
     35
     36        def compile_messages_in_dir(basedir):
     37            for dirpath, dirnames, filenames in os.walk(basedir):
     38                for f in filenames:
     39                    if f.endswith('.po'):
     40                        sys.stderr.write('processing file %s in %s\n' % (f, dirpath))
     41                        pf = os.path.splitext(os.path.join(dirpath, f))[0]
     42                        # Store the names of the .mo and .po files in an environment
     43                        # variable, rather than doing a string replacement into the
     44                        # command, so that we can take advantage of shell quoting, to
     45                        # quote any malicious characters/escaping.
     46                        # See http://cyberelk.net/tim/articles/cmdline/ar01s02.html
     47                        os.environ['djangocompilemo'] = pf + '.mo'
     48                        os.environ['djangocompilepo'] = pf + '.po'
     49                        if sys.platform == 'win32': # Different shell-variable syntax
     50                            cmd = 'msgfmt --check-format -o "%djangocompilemo%" "%djangocompilepo%"'
     51                        else:
     52                            cmd = 'msgfmt --check-format -o "$djangocompilemo" "$djangocompilepo"'
     53                        os.system(cmd)
     54
     55        for basedir in basedirs:
     56            if locale:
     57                basedir = os.path.join(basedir, locale, 'LC_MESSAGES')
     58            compile_messages_in_dir(basedir)
  • new file django/core/management/commands/messagesmake.py

    diff -r 8cd5ecf7b694 django/core/management/commands/messagesmake.py
    - +  
     1import re
     2import os
     3import sys
     4from itertools import dropwhile
     5from optparse import make_option
     6from django.core.management.base import CommandError, BaseCommand, get_locale_dir
     7from django.utils.translation import templatize
     8
     9pythonize_re = re.compile(r'\n\s*//')
     10
     11class Command(BaseCommand):
     12    option_list = BaseCommand.option_list + (
     13        make_option('--locale', '-l', default=None, dest='locale',
     14            help='Creates or updates the message files only for the given locale (e.g. pt_BR).'),
     15        make_option('--domain', '-d', default='django', dest='domain',
     16            help='The domain of the message files (default: "django").'),
     17        make_option('--verbosity', '-v', action='store', dest='verbosity', default='1',
     18            type='choice', choices=['0', '1', '2'],
     19            help='Verbosity level; 0=minimal output, 1=normal output, 2=all output'),
     20        make_option('--all', '-a', action='store_true', dest='all', default=False,
     21            help='Reexamines all source code and templates for new translation strings and updates all message files for all available languages.'),
     22    )
     23    help = "Runs over the entire source tree of the current directory and pulls out all strings marked for translation. It creates (or updates) a message file in the conf/locale (in the django tree) or locale (for project and application) directory."
     24
     25    requires_model_validation = False
     26    can_import_settings = False
     27
     28    def handle(self, *args, **options):
     29        if len(args) != 0:
     30            raise CommandError("Command doesn't accept any arguments")
     31
     32        localedir = get_locale_dir()
     33        locale = options.get('locale', None)
     34        domain = options.get('domain', 'django')
     35        verbosity = int(options.get('verbosity', 1))
     36        all = options.get('all', False)
     37
     38        if domain not in ('django', 'djangojs'):
     39            raise CommandError("currently messagesmake only supports domains 'django' and 'djangojs'")
     40        if (locale is None and not all) or domain is None:
     41            # backwards compatible error message
     42            if not sys.argv[0].endswith("make-messages.py"):
     43                message = "Type '%s help %s' for usage.\n" % (os.path.basename(sys.argv[0]), sys.argv[1])
     44            else:
     45                message = "usage: make-messages.py -l <language>\n   or: make-messages.py -a\n"
     46            sys.stderr.write(message)
     47            sys.exit(1)
     48
     49        languages = []
     50
     51        if locale is not None:
     52            languages.append(locale)
     53        elif all:
     54            languages = [el for el in os.listdir(localedir) if not el.startswith('.')]
     55
     56        for locale in languages:
     57            if verbosity > 0:
     58                print "processing language", locale
     59            basedir = os.path.join(localedir, locale, 'LC_MESSAGES')
     60            if not os.path.isdir(basedir):
     61                os.makedirs(basedir)
     62
     63            pofile = os.path.join(basedir, '%s.po' % domain)
     64            potfile = os.path.join(basedir, '%s.pot' % domain)
     65
     66            if os.path.exists(potfile):
     67                os.unlink(potfile)
     68
     69            all_files = []
     70            for (dirpath, dirnames, filenames) in os.walk("."):
     71                all_files.extend([(dirpath, f) for f in filenames])
     72            all_files.sort()
     73            for dirpath, file in all_files:
     74                if domain == 'djangojs' and file.endswith('.js'):
     75                    if verbosity > 1:
     76                        sys.stdout.write('processing file %s in %s\n' % (file, dirpath))
     77                    src = open(os.path.join(dirpath, file), "rb").read()
     78                    src = pythonize_re.sub('\n#', src)
     79                    open(os.path.join(dirpath, '%s.py' % file), "wb").write(src)
     80                    thefile = '%s.py' % file
     81                    cmd = 'xgettext %s -d %s -L Perl --keyword=gettext_noop --keyword=gettext_lazy --keyword=ngettext_lazy:1,2 --from-code UTF-8 -o - "%s"' % (
     82                        os.path.exists(potfile) and '--omit-header' or '', domain, os.path.join(dirpath, thefile))
     83                    (stdin, stdout, stderr) = os.popen3(cmd, 't')
     84                    msgs = stdout.read()
     85                    errors = stderr.read()
     86                    if errors:
     87                        print "errors happened while running xgettext on %s" % file
     88                        print errors
     89                        sys.exit(8)
     90                    old = '#: '+os.path.join(dirpath, thefile)[2:]
     91                    new = '#: '+os.path.join(dirpath, file)[2:]
     92                    msgs = msgs.replace(old, new)
     93                    if msgs:
     94                        open(potfile, 'ab').write(msgs)
     95                    os.unlink(os.path.join(dirpath, thefile))
     96                elif domain == 'django' and (file.endswith('.py') or file.endswith('.html')):
     97                    thefile = file
     98                    if file.endswith('.html'):
     99                        src = open(os.path.join(dirpath, file), "rb").read()
     100                        thefile = '%s.py' % file
     101                        open(os.path.join(dirpath, thefile), "wb").write(templatize(src))
     102                    if verbosity > 1:
     103                        sys.stdout.write('processing file %s in %s\n' % (file, dirpath))
     104                    cmd = 'xgettext -d %s -L Python --keyword=gettext_noop --keyword=gettext_lazy --keyword=ngettext_lazy:1,2 --keyword=ugettext_noop --keyword=ugettext_lazy --keyword=ungettext_lazy:1,2 --from-code UTF-8 -o - "%s"' % (
     105                        domain, os.path.join(dirpath, thefile))
     106                    (stdin, stdout, stderr) = os.popen3(cmd, 't')
     107                    msgs = stdout.read()
     108                    errors = stderr.read()
     109                    if errors:
     110                        print "errors happened while running xgettext on %s" % file
     111                        print errors
     112                        sys.exit(8)
     113                    if thefile != file:
     114                        old = '#: '+os.path.join(dirpath, thefile)[2:]
     115                        new = '#: '+os.path.join(dirpath, file)[2:]
     116                        msgs = msgs.replace(old, new)
     117                    if os.path.exists(potfile):
     118                        # Strip the header
     119                        msgs = '\n'.join(dropwhile(len, msgs.split('\n')))
     120                    else:
     121                        msgs = msgs.replace('charset=CHARSET', 'charset=UTF-8')
     122                    if msgs:
     123                        open(potfile, 'ab').write(msgs)
     124                    if thefile != file:
     125                        os.unlink(os.path.join(dirpath, thefile))
     126
     127            if os.path.exists(potfile):
     128                (stdin, stdout, stderr) = os.popen3('msguniq --to-code=utf-8 "%s"' % potfile, 'b')
     129                msgs = stdout.read()
     130                errors = stderr.read()
     131                if errors:
     132                    print "errors happened while running msguniq"
     133                    print errors
     134                    sys.exit(8)
     135                open(potfile, 'w').write(msgs)
     136                if os.path.exists(pofile):
     137                    (stdin, stdout, stderr) = os.popen3('msgmerge -q "%s" "%s"' % (pofile, potfile), 'b')
     138                    msgs = stdout.read()
     139                    errors = stderr.read()
     140                    if errors:
     141                        print "errors happened while running msgmerge"
     142                        print errors
     143                        sys.exit(8)
     144                open(pofile, 'wb').write(msgs)
     145                os.unlink(potfile)
  • docs/django-admin.txt

    diff -r 8cd5ecf7b694 docs/django-admin.txt
    a b your admin's index page. See `Tutorial 2 
    8484your admin's index page. See `Tutorial 2`_ for more information.
    8585
    8686.. _Tutorial 2: ../tutorial02/
     87
     88cleanup
     89-------
     90
     91Can be run as a cronjob or directly to clean out old data from the database
     92(only expired sessions at the moment).
    8793
    8894createcachetable <tablename>
    8995----------------------------
    Example usage:: 
    320326Example usage::
    321327
    322328    django-admin.py loaddata --verbosity=2
     329
     330messagescompile
     331---------------
     332
     333Compiles .po files created with ``messagesmake`` to .mo files for use with
     334the builtin gettext support.
     335
     336.. i18n documentation: ../i18n/#compiling-message-files
     337
     338--locale
     339~~~~~~~~
     340
     341Use the ``--locale`` or ``-l`` option to specify the locale to process.
     342If not provided all locales are processed.
     343
     344Example usage::
     345
     346    django-admin.py messagescompile --locale=br_PT
     347
     348messagesmake
     349------------
     350
     351Runs over the entire source tree of the current directory and pulls out all
     352strings marked for translation. It creates (or updates) a message file in the
     353conf/locale (in the django tree) or locale (for project and application)
     354directory. After making changes to the messages files you need to compile them
     355with ``messagescompile`` for use with the builtin gettext support.
     356
     357.. i18n documentation: ../i18n/#message-files
     358
     359--all
     360~~~~~
     361
     362Use the ``--all`` or ``-a`` option to update the message files for all
     363available languages.
     364
     365Example usage::
     366
     367    django-admin.py messagesmake --all
     368
     369--locale
     370~~~~~~~~
     371
     372Use the ``--locale`` or ``-l`` option to specify the locale to process.
     373
     374Example usage::
     375
     376    django-admin.py messagesmake --locale=br_PT
     377
     378--domain
     379~~~~~~~~
     380
     381Use the ``--domain`` or ``-d`` option to change the domain of the messages files.
     382Currently supported:
     383
     384        * ``django`` for all ``*.py`` and ``*.html`` files (default)
     385        * ``djangojs`` for ``*.js`` files
     386
     387--verbosity
     388~~~~~~~~~~~
     389
     390Use ``--verbosity`` or ``-v`` to specify the amount of notification and debug
     391information that ``django-admin.py`` should print to the console.
     392
     393        * ``0`` means no input.
     394        * ``1`` means normal input (default).
     395        * ``2`` means verbose input.
     396
     397Example usage::
     398
     399    django-admin.py messagesmake --verbosity=2
     400
     401
    323402
    324403reset <appname appname ...>
    325404---------------------------
  • docs/i18n.txt

    diff -r 8cd5ecf7b694 docs/i18n.txt
    a b Translation works on variables. Again, h 
    122122
    123123(The caveat with using variables or computed values, as in the previous two
    124124examples, is that Django's translation-string-detecting utility,
    125 ``make-messages.py``, won't be able to find these strings. More on
    126 ``make-messages`` later.)
     125``djangoadmin.py messagesmake``, won't be able to find these strings. More on
     126``messagesmake`` later.)
    127127
    128128The strings you pass to ``_()`` or ``ugettext()`` can take placeholders,
    129129specified with Python's standard named-string interpolation syntax. Example::
    available translation strings and how th 
    392392available translation strings and how they should be represented in the given
    393393language. Message files have a ``.po`` file extension.
    394394
    395 Django comes with a tool, ``bin/make-messages.py``, that automates the creation
     395Django comes with a tool, ``bin/djangoadmin.py messagesmake``, that automates the creation
    396396and upkeep of these files.
    397397
    398398To create or update a message file, run this command::
    399399
    400     bin/make-messages.py -l de
     400    bin/djangoadmin.py messagesmake -l de
    401401
    402402...where ``de`` is the language code for the message file you want to create.
    403403The language code, in this case, is in locale format. For example, it's
    do the same, but the location of the loc 
    422422
    423423.. admonition:: No gettext?
    424424
    425     If you don't have the ``gettext`` utilities installed, ``make-messages.py``
     425    If you don't have the ``gettext`` utilities installed, ``djangoadmin.py messagesmake``
    426426    will create empty files. If that's the case, either install the ``gettext``
    427427    utilities or just copy the English message file
    428428    (``conf/locale/en/LC_MESSAGES/django.po``) and use it as a starting point;
    For example, if your Django app containe 
    439439
    440440    _("Welcome to my site.")
    441441
    442 ...then ``make-messages.py`` will have created a ``.po`` file containing the
     442...then ``djangoadmin.py messagesmake`` will have created a ``.po`` file containing the
    443443following snippet -- a message::
    444444
    445445    #: path/to/python/module.py:23
    To reexamine all source code and templat 
    475475To reexamine all source code and templates for new translation strings and
    476476update all message files for **all** languages, run this::
    477477
    478     make-messages.py -a
     478    djangoadmin.py messagesmake -a
    479479
    480480Compiling message files
    481481-----------------------
    482482
    483483After you create your message file -- and each time you make changes to it --
    484484you'll need to compile it into a more efficient form, for use by ``gettext``.
    485 Do this with the ``bin/compile-messages.py`` utility.
     485Do this with the ``bin/djangoadmin.py messagescompile`` utility.
    486486
    487487This tool runs over all available ``.po`` files and creates ``.mo`` files,
    488488which are binary files optimized for use by ``gettext``. In the same directory
    489 from which you ran ``make-messages.py``, run ``compile-messages.py`` like
     489from which you ran ``djangoadmin.py messagesmake``, run ``djangoadmin.py messagescompile`` like
    490490this::
    491491
    492    bin/compile-messages.py
     492   bin/djangoadmin.py messagescompile
    493493
    494494That's it. Your translations are ready for use.
    495495
    Notes: 
    597597              ('en', ugettext('English')),
    598598          )
    599599
    600       With this arrangement, ``make-messages.py`` will still find and mark
     600      With this arrangement, ``djangoadmin.py messagesmake`` will still find and mark
    601601      these strings for translation, but the translation won't happen at
    602602      runtime -- so you'll have to remember to wrap the languages in the *real*
    603603      ``ugettext()`` in any code that uses ``LANGUAGES`` at runtime.
    All message file repositories are struct 
    676676      searched in that order for ``<language>/LC_MESSAGES/django.(po|mo)``
    677677    * ``$PYTHONPATH/django/conf/locale/<language>/LC_MESSAGES/django.(po|mo)``
    678678
    679 To create message files, you use the same ``make-messages.py`` tool as with the
     679To create message files, you use the same ``djangoadmin.py messagesmake`` tool as with the
    680680Django message files. You only need to be in the right place -- in the directory
    681681where either the ``conf/locale`` (in case of the source tree) or the ``locale/``
    682682(in case of app messages or project messages) directory are located. And you
    683 use the same ``compile-messages.py`` to produce the binary ``django.mo`` files
     683use the same ``djangoadmin.py messagescompile`` to produce the binary ``django.mo`` files
    684684that are used by ``gettext``.
    685685
    686686You can also run ``compile-message.py --settings=path.to.settings`` to make
    files. If your applications need to be d 
    694694files. If your applications need to be delivered to other users and will
    695695be used in other projects, you might want to use app-specific translations.
    696696But using app-specific translations and project translations could produce
    697 weird problems with ``make-messages``: ``make-messages`` will traverse all
     697weird problems with ``messagesmake``: ``messagesmake`` will traverse all
    698698directories below the current path and so might put message IDs into the
    699699project message file that are already in application message files.
    700700
    701701The easiest way out is to store applications that are not part of the project
    702702(and so carry their own translations) outside the project tree. That way,
    703 ``make-messages`` on the project level will only translate strings that are
     703``messagesmake`` on the project level will only translate strings that are
    704704connected to your explicit project and not strings that are distributed
    705705independently.
    706706
    Creating JavaScript translation catalogs 
    832832----------------------------------------
    833833
    834834You create and update the translation catalogs the same way as the other
    835 Django translation catalogs -- with the make-messages.py tool. The only
     835Django translation catalogs -- with the ``djangoadmin.py messagesmake`` tool. The only
    836836difference is you need to provide a ``-d djangojs`` parameter, like this::
    837837
    838     make-messages.py -d djangojs -l de
     838    djangoadmin.py messagesmake -d djangojs -l de
    839839
    840840This would create or update the translation catalog for JavaScript for German.
    841 After updating translation catalogs, just run ``compile-messages.py`` the same
     841After updating translation catalogs, just run ``djangoadmin.py messagescompile`` the same
    842842way as you do with normal Django translation catalogs.
    843843
    844844Specialties of Django translation
  • docs/man/django-admin.1

    diff -r 8cd5ecf7b694 docs/man/django-admin.1
    a b  
    1 .TH "django-admin.py" "1" "June 2007" "Django Project" ""
     1.TH "django-admin.py" "1" "February 2008" "Django Project" ""
    22.SH "NAME"
    33django\-admin.py \- Utility script for the Django web framework
    44.SH "SYNOPSIS"
    script found at the top level of each Dj 
    2121.BI "adminindex [" "appname ..." "]"
    2222Prints the admin\-index template snippet for the given app name(s).
    2323.TP
     24.BI cleanup
     25Cleans out old data from the database (only expired sessions at the moment).
     26.TP
    2427.BI "createcachetable [" "tablename" "]"
    2528Creates the table needed to use the SQL cache backend
    2629.TP
    Executes 
    4245Executes
    4346.B sqlall
    4447for the given app(s) in the current database.
     48.TP
     49.BI "messagescompile [" "\-\-locale=LOCALE" "]"
     50Compiles .po files to .mo files for use with builtin gettext support.
     51.TP
     52.BI "messagesmake [" "\-\-locale=LOCALE" "] [" "\-\-domain=DOMAIN" "] [" "\-\-all" "]"
     53Runs over the entire source tree of the current directory and pulls out all
     54strings marked for translation. It creates (or updates) a message file in the
     55conf/locale (in the django tree) or locale (for project and application) directory.
    4556.TP
    4657.BI "reset [" "appname ..." "]"
    4758Executes
    Verbosity level: 0=minimal output, 1=nor 
    136147.TP
    137148.I \-\-adminmedia=ADMIN_MEDIA_PATH
    138149Specifies the directory from which to serve admin media when using the development server.
    139 
     150.TP
     151.I \-l, \-\-locale=LOCALE
     152The locale to process when using messagesmake or messagecompile.
     153.TP
     154.I \-d, \-\-domain=DOMAIN
     155The domain of the message files (default: "django") when using messagesmake.
     156.TP
     157.I \-a, \-\-all
     158Process all available locales when using messagesmake.
    140159.SH "ENVIRONMENT"
    141160.TP
    142161.I DJANGO_SETTINGS_MODULE
  • docs/settings.txt

    diff -r 8cd5ecf7b694 docs/settings.txt
    a b settings file:: 
    614614        ('en', gettext('English')),
    615615    )
    616616
    617 With this arrangement, ``make-messages.py`` will still find and mark these
     617With this arrangement, ``django-admin.py messagesmake`` will still find and mark these
    618618strings for translation, but the translation won't happen at runtime -- so
    619619you'll have to remember to wrap the languages in the *real* ``gettext()`` in
    620620any code that uses ``LANGUAGES`` at runtime.
  • extras/django_bash_completion

    diff -r 8cd5ecf7b694 extras/django_bash_completion
    a b _django_completion() 
    4242    prev="${COMP_WORDS[COMP_CWORD-1]}"
    4343
    4444    # Standalone options
    45     opts="--help --settings --pythonpath --noinput --noreload --format --indent --verbosity --adminmedia --version"
     45    opts="--help --settings --pythonpath --noinput --noreload --locale --all --domain --format --indent --verbosity --adminmedia --version"
     46
    4647    # Actions
    47     actions="adminindex createcachetable dbshell diffsettings \
    48              dumpdata flush inspectdb loaddata reset runfcgi runserver \
    49              shell sql sqlall sqlclear sqlcustom sqlflush sqlindexes \
    50              sqlreset sqlsequencereset startapp startproject \
    51              syncdb test validate"
     48    actions="adminindex createcachetable cleanup dbshell diffsettings \
     49             dumpdata flush inspectdb loaddata messagescompile messagesmake \
     50             reset runfcgi runserver shell sql sqlall sqlclear sqlcustom \
     51             sqlflush sqlindexes sqlreset sqlsequencereset startapp \
     52             startproject syncdb test validate"
     53
    5254    # Action's options
    5355    action_shell_opts="--plain"
    5456    action_runfcgi_opts="host port socket method maxspare minspare maxchildren daemonize pidfile workdir"
    _django_completion() 
    112114                return 0
    113115                ;;
    114116
    115             createcachetable|dbshell|diffsettings| \
    116             inspectdb|runserver|startapp|startproject|syncdb| \
     117            createcachetable|cleanup|dbshell|diffsettings| \
     118            inspectdb|messagescompile|messagesmake| \
     119            runserver|startapp|startproject|syncdb| \
    117120            validate)
    118121                COMPREPLY=()
    119122                return 0
Back to Top