Ticket #5522: django-admin.5.diff

File django-admin.5.diff, 38.7 KB (added by Jannis Leidel, 16 years ago)

As with Jacob discussed this patch moves the i18n helper functions to their appropriate subcommands and also includes [7473].

  • django/core/management/commands/makemessages.py

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

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

     
    66from django.core.exceptions import ImproperlyConfigured
    77from django.core.management.color import color_style
    88
     9try:
     10    set
     11except NameError:
     12    from sets import Set as set     # For Python 2.3
     13
    914class CommandError(Exception):
    1015    pass
    1116
  • django/bin/daily_cleanup.py

     
    77sessions at the moment).
    88"""
    99
    10 import datetime
    11 from django.db import transaction
    12 from django.contrib.sessions.models import Session
     10from django.core import management
    1311
    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()
    18 
    1912if __name__ == "__main__":
    20     clean_up()
     13    management.call_command('cleanup')
  • django/bin/compile-messages.py

     
    11#!/usr/bin/env python
    22
    3 import optparse
    43import os
    5 import sys
     4import optparse
     5from django.core.management.commands.compilemessages import compile_messages
    66
    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)
    49 
    507def main():
    518    parser = optparse.OptionParser()
    529    parser.add_option('-l', '--locale', dest='locale',
  • django/bin/make-messages.py

     
    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
    10 import sys
    11 import getopt
    12 from itertools import dropwhile
     4import optparse
     5from django.core.management.commands.makemessages import make_messages
    136
    14 pythonize_re = re.compile(r'\n\s*//')
     7def main():
     8    parser = optparse.OptionParser()
     9    parser.add_option('-l', '--locale', dest='locale',
     10        help='Creates or updates the message files only for the \
     11            given locale (e.g. pt_BR).')
     12    parser.add_option('-d', '--domain', dest='domain', default='django',
     13        help='The domain of the message files (default: "django").')
     14    parser.add_option('-v', '--verbose', action='store_true', dest='verbose',
     15        default=False, help='Verbosity output')
     16    parser.add_option('-a', '--all', action='store_true', dest='all',
     17        default=False, help='Reexamines all source code and templates for \
     18            new translation strings and updates all message files for all \
     19            available languages.')
    1520
    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')
     21    options, args = parser.parse_args()
     22    if len(args):
     23        parser.error("This program takes no arguments")
     24    if options.verbose:
     25        verbosity = 2
    2326    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)
     27        verbosity = 1
     28   
     29    make_messages(locale=options.locale, domain=options.domain,
     30        verbosity=verbosity, all=options.all)
    3131
    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 -d %s -L Perl --keyword=gettext_noop --keyword=gettext_lazy --keyword=ngettext_lazy:1,2 --from-code UTF-8 -o - "%s"' % (domain, os.path.join(dirpath, thefile))
    89                 (stdin, stdout, stderr) = os.popen3(cmd, 't')
    90                 msgs = stdout.read()
    91                 errors = stderr.read()
    92                 if errors:
    93                     print "errors happened while running xgettext on %s" % file
    94                     print errors
    95                     sys.exit(8)
    96                 old = '#: '+os.path.join(dirpath, thefile)[2:]
    97                 new = '#: '+os.path.join(dirpath, file)[2:]
    98                 msgs = msgs.replace(old, new)
    99                 if os.path.exists(potfile):
    100                     # Strip the header
    101                     msgs = '\n'.join(dropwhile(len, msgs.split('\n')))
    102                 else:
    103                     msgs = msgs.replace('charset=CHARSET', 'charset=UTF-8')
    104                 if msgs:
    105                     open(potfile, 'ab').write(msgs)
    106                 os.unlink(os.path.join(dirpath, thefile))
    107             elif domain == 'django' and (file.endswith('.py') or file.endswith('.html')):
    108                 thefile = file
    109                 if file.endswith('.html'):
    110                     src = open(os.path.join(dirpath, file), "rb").read()
    111                     thefile = '%s.py' % file
    112                     open(os.path.join(dirpath, thefile), "wb").write(templatize(src))
    113                 if verbose:
    114                     sys.stdout.write('processing file %s in %s\n' % (file, dirpath))
    115                 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"' % (
    116                     domain, os.path.join(dirpath, thefile))
    117                 (stdin, stdout, stderr) = os.popen3(cmd, 't')
    118                 msgs = stdout.read()
    119                 errors = stderr.read()
    120                 if errors:
    121                     print "errors happened while running xgettext on %s" % file
    122                     print errors
    123                     sys.exit(8)
    124                 if thefile != file:
    125                     old = '#: '+os.path.join(dirpath, thefile)[2:]
    126                     new = '#: '+os.path.join(dirpath, file)[2:]
    127                     msgs = msgs.replace(old, new)
    128                 if os.path.exists(potfile):
    129                     # Strip the header
    130                     msgs = '\n'.join(dropwhile(len, msgs.split('\n')))
    131                 else:
    132                     msgs = msgs.replace('charset=CHARSET', 'charset=UTF-8')
    133                 if msgs:
    134                     open(potfile, 'ab').write(msgs)
    135                 if thefile != file:
    136                     os.unlink(os.path.join(dirpath, thefile))
    137 
    138         if os.path.exists(potfile):
    139             (stdin, stdout, stderr) = os.popen3('msguniq --to-code=utf-8 "%s"' % potfile, 'b')
    140             msgs = stdout.read()
    141             errors = stderr.read()
    142             if errors:
    143                 print "errors happened while running msguniq"
    144                 print errors
    145                 sys.exit(8)
    146             open(potfile, 'w').write(msgs)
    147             if os.path.exists(pofile):
    148                 (stdin, stdout, stderr) = os.popen3('msgmerge -q "%s" "%s"' % (pofile, potfile), 'b')
    149                 msgs = stdout.read()
    150                 errors = stderr.read()
    151                 if errors:
    152                     print "errors happened while running msgmerge"
    153                     print errors
    154                     sys.exit(8)
    155             open(pofile, 'wb').write(msgs)
    156             os.unlink(potfile)
    157 
    15832if __name__ == "__main__":
    159     make_messages()
     33    main()
  • extras/django_bash_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 compilemessages dbshell \
     49             diffsettings dumpdata flush inspectdb loaddata makemessages \
     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"
     
    112114                return 0
    113115                ;;
    114116
    115             createcachetable|dbshell|diffsettings| \
    116             inspectdb|runserver|startapp|startproject|syncdb| \
     117            createcachetable|cleanup|compilemessages|dbshell| \
     118            diffsettings|inspectdb|makemessages| \
     119            runserver|startapp|startproject|syncdb| \
    117120            validate)
    118121                COMPREPLY=()
    119122                return 0
  • docs/man/django-admin.1

     
    1 .TH "django-admin.py" "1" "June 2007" "Django Project" ""
     1.TH "django-admin.py" "1" "March 2008" "Django Project" ""
    22.SH "NAME"
    33django\-admin.py \- Utility script for the Django web framework
    44.SH "SYNOPSIS"
     
    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
     27.BI "compilemessages [" "\-\-locale=LOCALE" "]"
     28Compiles .po files to .mo files for use with builtin gettext support.
     29.TP
    2430.BI "createcachetable [" "tablename" "]"
    2531Creates the table needed to use the SQL cache backend
    2632.TP
     
    4349.B sqlall
    4450for the given app(s) in the current database.
    4551.TP
     52.BI "makemessages [" "\-\-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.
     56.TP
    4657.BI "reset [" "appname ..." "]"
    4758Executes
    4859.B sqlreset
     
    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 makemessages or compilemessages.
     153.TP
     154.I \-d, \-\-domain=DOMAIN
     155The domain of the message files (default: "django") when using makemessages.
     156.TP
     157.I \-a, \-\-all
     158Process all available locales when using makemessages.
    140159.SH "ENVIRONMENT"
    141160.TP
    142161.I DJANGO_SETTINGS_MODULE
  • docs/i18n.txt

     
    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``django-admin.py makemessages``, won't be able to find these strings. More on
     126``makemessages`` later.)
    127127
    128128The strings you pass to ``_()`` or ``ugettext()`` can take placeholders,
    129129specified with Python's standard named-string interpolation syntax. Example::
     
    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
    396 and upkeep of these files.
     395Django comes with a tool, ``django-admin.py makemessages``, that automates the
     396creation and upkeep of these files.
    397397
    398398To create or update a message file, run this command::
    399399
    400     bin/make-messages.py -l de
     400    django-admin.py makemessages -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
     
    422422
    423423.. admonition:: No gettext?
    424424
    425     If you don't have the ``gettext`` utilities installed, ``make-messages.py``
    426     will create empty files. If that's the case, either install the ``gettext``
    427     utilities or just copy the English message file
    428     (``conf/locale/en/LC_MESSAGES/django.po``) and use it as a starting point;
    429     it's just an empty translation file.
     425    If you don't have the ``gettext`` utilities installed,
     426    ``django-admin.py makemessages`` will create empty files. If that's the
     427    case, either install the ``gettext`` utilities or just copy the English
     428    message file (``conf/locale/en/LC_MESSAGES/django.po``) and use it as a
     429    starting point; it's just an empty translation file.
    430430
    431431The format of ``.po`` files is straightforward. Each ``.po`` file contains a
    432432small bit of metadata, such as the translation maintainer's contact
     
    439439
    440440    _("Welcome to my site.")
    441441
    442 ...then ``make-messages.py`` will have created a ``.po`` file containing the
    443 following snippet -- a message::
     442...then ``django-admin.py makemessages`` will have created a ``.po`` file
     443containing the following snippet -- a message::
    444444
    445445    #: path/to/python/module.py:23
    446446    msgid "Welcome to my site."
     
    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    django-admin.py makemessages -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 ``django-admin.py compilemessages`` 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
    490 this::
     489from which you ran ``django-admin.py makemessages``, run
     490``django-admin.py compilemessages`` like this::
    491491
    492    bin/compile-messages.py
     492   django-admin.py compilemessages
    493493
    494494That's it. Your translations are ready for use.
    495495
     
    597597              ('en', ugettext('English')),
    598598          )
    599599
    600       With this arrangement, ``make-messages.py`` will still find and mark
    601       these strings for translation, but the translation won't happen at
    602       runtime -- so you'll have to remember to wrap the languages in the *real*
     600      With this arrangement, ``django-admin.py makemessages`` will still find
     601      and mark these strings for translation, but the translation won't happen
     602      at runtime -- so you'll have to remember to wrap the languages in the *real*
    603603      ``ugettext()`` in any code that uses ``LANGUAGES`` at runtime.
    604604
    605605    * The ``LocaleMiddleware`` can only select languages for which there is a
     
    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
    680 Django message files. You only need to be in the right place -- in the directory
    681 where either the ``conf/locale`` (in case of the source tree) or the ``locale/``
    682 (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
    684 that are used by ``gettext``.
     679To create message files, you use the same ``django-admin.py makemessages``
     680tool as with the Django message files. You only need to be in the right place
     681-- in the directory where either the ``conf/locale`` (in case of the source
     682tree) or the ``locale/`` (in case of app messages or project messages)
     683directory are located. And you use the same ``django-admin.py compilemessages``
     684to produce the binary ``django.mo`` files that are used by ``gettext``.
    685685
    686686You can also run ``compile-message.py --settings=path.to.settings`` to make
    687687the compiler process all the directories in your ``LOCALE_PATHS`` setting.
     
    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 ``makemessages``: ``makemessages`` 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
    704 connected to your explicit project and not strings that are distributed
    705 independently.
     703``django-admin.py makemessages`` on the project level will only translate
     704strings that are connected to your explicit project and not strings that are
     705distributed independently.
    706706
    707707The ``set_language`` redirect view
    708708==================================
     
    857857----------------------------------------
    858858
    859859You create and update the translation catalogs the same way as the other
    860 Django translation catalogs -- with the make-messages.py tool. The only
    861 difference is you need to provide a ``-d djangojs`` parameter, like this::
     860Django translation catalogs -- with the django-admin.py makemessages tool. The
     861only difference is you need to provide a ``-d djangojs`` parameter, like this::
    862862
    863     make-messages.py -d djangojs -l de
     863    django-admin.py makemessages -d djangojs -l de
    864864
    865865This would create or update the translation catalog for JavaScript for German.
    866 After updating translation catalogs, just run ``compile-messages.py`` the same
    867 way as you do with normal Django translation catalogs.
     866After updating translation catalogs, just run ``django-admin.py compilemessages``
     867the same way as you do with normal Django translation catalogs.
    868868
    869869Specialties of Django translation
    870870==================================
  • docs/contributing.txt

     
    331331    * Create translations using the methods described in the
    332332      `i18n documentation`_.
    333333    * Create a diff of the ``.po`` file against the current Subversion trunk.
    334     * Make sure that `` bin/compile-messages.py -l <lang>`` runs without
     334    * Make sure that `` django-admin.py compilemessages -l <lang>`` runs without
    335335      producing any warnings.
    336336    * Attach the patch to a ticket in Django's ticket system.
    337337
  • docs/settings.txt

     
    638638        ('en', gettext('English')),
    639639    )
    640640
    641 With this arrangement, ``make-messages.py`` will still find and mark these
    642 strings for translation, but the translation won't happen at runtime -- so
    643 you'll have to remember to wrap the languages in the *real* ``gettext()`` in
    644 any code that uses ``LANGUAGES`` at runtime.
     641With this arrangement, ``django-admin.py makemessages`` will still find and
     642mark these strings for translation, but the translation won't happen at
     643runtime -- so you'll have to remember to wrap the languages in the *real*
     644``gettext()`` in any code that uses ``LANGUAGES`` at runtime.
    645645
    646646LOCALE_PATHS
    647647------------
  • docs/sessions.txt

     
    349349logs out manually, Django deletes the row. But if the user does *not* log out,
    350350the row never gets deleted.
    351351
    352 Django provides a sample clean-up script in ``django/bin/daily_cleanup.py``.
     352Django provides a sample clean-up script in ``django-admin.py cleanup``.
    353353That script deletes any session in the session table whose ``expire_date`` is
    354354in the past -- but your application may have different requirements.
    355355
  • docs/django-admin.txt

     
    8585
    8686.. _Tutorial 2: ../tutorial02/
    8787
     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).
     93
     94compilemessages
     95---------------
     96
     97Compiles .po files created with ``makemessages`` to .mo files for use with
     98the builtin gettext support. See the `i18n documentation`_ for details.
     99
     100--locale
     101~~~~~~~~
     102
     103Use the ``--locale`` or ``-l`` option to specify the locale to process.
     104If not provided all locales are processed.
     105
     106Example usage::
     107
     108    django-admin.py compilemessages --locale=br_PT
     109
    88110createcachetable <tablename>
    89111----------------------------
    90112
     
    346368
    347369    django-admin.py loaddata --verbosity=2
    348370
     371makemessages
     372------------
     373
     374Runs over the entire source tree of the current directory and pulls out all
     375strings marked for translation. It creates (or updates) a message file in the
     376conf/locale (in the django tree) or locale (for project and application)
     377directory. After making changes to the messages files you need to compile them
     378with ``compilemessages`` for use with the builtin gettext support. See the
     379`i18n documentation`_ for details.
     380
     381.. _i18n documentation: ../i18n/#how-to-create-language-files
     382
     383--all
     384~~~~~
     385
     386Use the ``--all`` or ``-a`` option to update the message files for all
     387available languages.
     388
     389Example usage::
     390
     391    django-admin.py makemessages --all
     392
     393--locale
     394~~~~~~~~
     395
     396Use the ``--locale`` or ``-l`` option to specify the locale to process.
     397
     398Example usage::
     399
     400    django-admin.py makemessages --locale=br_PT
     401
     402--domain
     403~~~~~~~~
     404
     405Use the ``--domain`` or ``-d`` option to change the domain of the messages files.
     406Currently supported:
     407
     408        * ``django`` for all ``*.py`` and ``*.html`` files (default)
     409        * ``djangojs`` for ``*.js`` files
     410
     411--verbosity
     412~~~~~~~~~~~
     413
     414Use ``--verbosity`` or ``-v`` to specify the amount of notification and debug
     415information that ``django-admin.py`` should print to the console.
     416
     417        * ``0`` means no input.
     418        * ``1`` means normal input (default).
     419        * ``2`` means verbose input.
     420
     421Example usage::
     422
     423    django-admin.py makemessages --verbosity=2
     424
    349425reset <appname appname ...>
    350426---------------------------
    351427
Back to Top