Ticket #5522: django-admin.diff

File django-admin.diff, 37.2 KB (added by Jannis Leidel, 17 years ago)

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

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

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

     
     1#!/usr/bin/env python
     2import os
     3import sys
     4from optparse import make_option
     5from django.core.management.base import BaseCommand, CommandError, get_locale_dir
     6from django.core.management.color import no_style
     7
     8class Command(BaseCommand):
     9    option_list = BaseCommand.option_list + (
     10        make_option('-l', '--locale', dest='locale',
     11            help='The locale to process. Default is to process all.'),
     12    )
     13    help = 'Compiles .po files to .mo files for use with builtin gettext support.'
     14
     15    requires_model_validation = False
     16    can_import_settings = False
     17
     18    def handle(self, **options):
     19        basedir = get_locale_dir()
     20        locale = options.get('locale', None)
     21        if locale is not None:
     22            basedir = os.path.join(basedir, locale, 'LC_MESSAGES')
     23
     24        for dirpath, dirnames, filenames in os.walk(basedir):
     25            for f in filenames:
     26                if f.endswith('.po'):
     27                    sys.stderr.write('processing file %s in %s\n' % (f, dirpath))
     28                    pf = os.path.splitext(os.path.join(dirpath, f))[0]
     29                    # Store the names of the .mo and .po files in an environment
     30                    # variable, rather than doing a string replacement into the
     31                    # command, so that we can take advantage of shell quoting, to
     32                    # quote any malicious characters/escaping.
     33                    # See http://cyberelk.net/tim/articles/cmdline/ar01s02.html
     34                    os.environ['djangocompilemo'] = pf + '.mo'
     35                    os.environ['djangocompilepo'] = pf + '.po'
     36                    if sys.platform == 'win32': # Different shell-variable syntax
     37                        cmd = 'msgfmt --check-format -o "%djangocompilemo%" "%djangocompilepo%"'
     38                    else:
     39                        cmd = 'msgfmt --check-format -o "$djangocompilemo" "$djangocompilepo"'
     40                    os.system(cmd)
  • 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

     
    203203            except OSError:
    204204                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))
    205205
     206def get_locale_dir():
     207    "Returns the locale directory from the Django SVN tree or an application/project"
     208    if os.path.isdir(os.path.join('conf', 'locale')):
     209        basedir = os.path.abspath(os.path.join('conf', 'locale'))
     210    elif os.path.isdir('locale'):
     211        basedir = os.path.abspath('locale')
     212    else:
     213        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.")
     214    return basedir
     215
    206216def _make_writeable(filename):
    207217    "Makes sure that the file is writeable. Useful if our source is read-only."
    208218    import stat
  • 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/unique-messages.py

     
    11#!/usr/bin/env python
     2from django.core import management
    23
    3 import os
    4 import sys
    5 
    6 def unique_messages():
    7     basedir = None
    8 
    9     if os.path.isdir(os.path.join('conf', 'locale')):
    10         basedir = os.path.abspath(os.path.join('conf', 'locale'))
    11     elif os.path.isdir('locale'):
    12         basedir = os.path.abspath('locale')
    13     else:
    14         print "this script should be run from the django svn tree or your project or app tree"
    15         sys.exit(1)
    16 
    17     for (dirpath, dirnames, filenames) in os.walk(basedir):
    18         for f in filenames:
    19             if f.endswith('.po'):
    20                 sys.stderr.write('processing file %s in %s\n' % (f, dirpath))
    21                 pf = os.path.splitext(os.path.join(dirpath, f))[0]
    22                 cmd = 'msguniq "%s.po"' % pf
    23                 stdout = os.popen(cmd)
    24                 msg = stdout.read()
    25                 open('%s.po' % pf, 'w').write(msg)
    26 
    274if __name__ == "__main__":
    28     unique_messages()
     5    management.call_command('messagesunique')
  • django/bin/compile-messages.py

     
    11#!/usr/bin/env python
    2 
    3 import optparse
    42import os
    53import sys
     4import optparse
     5from django.core import management
    66
    7 def compile_messages(locale=None):
    8     basedir = None
    9 
    10     if os.path.isdir(os.path.join('conf', 'locale')):
    11         basedir = os.path.abspath(os.path.join('conf', 'locale'))
    12     elif os.path.isdir('locale'):
    13         basedir = os.path.abspath('locale')
    14     else:
    15         print "This script should be run from the Django SVN tree or your project or app tree."
    16         sys.exit(1)
    17 
    18     if locale is not None:
    19         basedir = os.path.join(basedir, locale, 'LC_MESSAGES')
    20 
    21     for dirpath, dirnames, filenames in os.walk(basedir):
    22         for f in filenames:
    23             if f.endswith('.po'):
    24                 sys.stderr.write('processing file %s in %s\n' % (f, dirpath))
    25                 pf = os.path.splitext(os.path.join(dirpath, f))[0]
    26                 # Store the names of the .mo and .po files in an environment
    27                 # variable, rather than doing a string replacement into the
    28                 # command, so that we can take advantage of shell quoting, to
    29                 # quote any malicious characters/escaping.
    30                 # See http://cyberelk.net/tim/articles/cmdline/ar01s02.html
    31                 os.environ['djangocompilemo'] = pf + '.mo'
    32                 os.environ['djangocompilepo'] = pf + '.po'
    33                 if sys.platform == 'win32': # Different shell-variable syntax
    34                     cmd = 'msgfmt --check-format -o "%djangocompilemo%" "%djangocompilepo%"'
    35                 else:
    36                     cmd = 'msgfmt --check-format -o "$djangocompilemo" "$djangocompilepo"'
    37                 os.system(cmd)
    38 
    397def main():
    408    parser = optparse.OptionParser()
    419    parser.add_option('-l', '--locale', dest='locale',
    42             help="The locale to process. Default is to process all.")
     10        help="The locale to process. Default is to process all.")
    4311    options, args = parser.parse_args()
    4412    if len(args):
    4513        parser.error("This program takes no arguments")
    46     compile_messages(options.locale)
     14    management.call_command('messagescompile', locale=options.locale)
    4715
    4816if __name__ == "__main__":
    4917    main()
  • django/bin/make-messages.py

     
    11#!/usr/bin/env python
    2 
    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
    92import os
    103import sys
    114import getopt
    12 from itertools import dropwhile
     5import optparse
     6from django.core import management
    137
    14 pythonize_re = re.compile(r'\n\s*//')
     8def main():
     9    parser = optparse.OptionParser()
     10    parser.add_option('-l', '--locale', dest='locale',
     11        help='Creates or updates the message files only for the given locale (e.g. pt_BR).')
     12    parser.add_option('-d', '--domain', dest='domain',
     13        help='The domain of the message files (default: "django").')
     14    parser.add_option('-v', '--verbose', action='store_true', dest='verbose', default=False,
     15        help='Verbosity output')
     16    parser.add_option('-a', '--all', action='store_true', dest='all', default=False,
     17        help='Reexamines all source code and templates for new translation strings and updates all message files for all available languages.')
    1518
    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')
     19    options, args = parser.parse_args()
     20    if len(args):
     21        parser.error("This program takes no arguments")
     22    if options.verbose:
     23        verbosity = 2
    2324    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)
     25        verbosity = 1
    3126
    32     (opts, args) = getopt.getopt(sys.argv[1:], 'l:d:va')
     27    management.call_command('messagesmake', locale=options.locale,
     28        domain=options.domain, verbosity=verbosity, all=options.all)
    3329
    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         for (dirpath, dirnames, filenames) in os.walk("."):
    78             for file in filenames:
    79                 if domain == 'djangojs' and file.endswith('.js'):
    80                     if verbose: sys.stdout.write('processing file %s in %s\n' % (file, dirpath))
    81                     src = open(os.path.join(dirpath, file), "rb").read()
    82                     src = pythonize_re.sub('\n#', src)
    83                     open(os.path.join(dirpath, '%s.py' % file), "wb").write(src)
    84                     thefile = '%s.py' % file
    85                     cmd = 'xgettext %s -d %s -L Perl --keyword=gettext_noop --keyword=gettext_lazy --keyword=ngettext_lazy:1,2 --from-code UTF-8 -o - "%s"' % (
    86                         os.path.exists(potfile) and '--omit-header' or '', domain, os.path.join(dirpath, thefile))
    87                     (stdin, stdout, stderr) = os.popen3(cmd, 't')
    88                     msgs = stdout.read()
    89                     errors = stderr.read()
    90                     if errors:
    91                         print "errors happened while running xgettext on %s" % file
    92                         print errors
    93                         sys.exit(8)
    94                     old = '#: '+os.path.join(dirpath, thefile)[2:]
    95                     new = '#: '+os.path.join(dirpath, file)[2:]
    96                     msgs = msgs.replace(old, new)
    97                     if msgs:
    98                         open(potfile, 'ab').write(msgs)
    99                     os.unlink(os.path.join(dirpath, thefile))
    100                 elif domain == 'django' and (file.endswith('.py') or file.endswith('.html')):
    101                     thefile = file
    102                     if file.endswith('.html'):
    103                         src = open(os.path.join(dirpath, file), "rb").read()
    104                         thefile = '%s.py' % file
    105                         open(os.path.join(dirpath, thefile), "wb").write(templatize(src))
    106                     if verbose:
    107                         sys.stdout.write('processing file %s in %s\n' % (file, dirpath))
    108                     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"' % (
    109                         domain, os.path.join(dirpath, thefile))
    110                     (stdin, stdout, stderr) = os.popen3(cmd, 't')
    111                     msgs = stdout.read()
    112                     errors = stderr.read()
    113                     if errors:
    114                         print "errors happened while running xgettext on %s" % file
    115                         print errors
    116                         sys.exit(8)
    117                     if thefile != file:
    118                         old = '#: '+os.path.join(dirpath, thefile)[2:]
    119                         new = '#: '+os.path.join(dirpath, file)[2:]
    120                         msgs = msgs.replace(old, new)
    121                     if os.path.exists(potfile):
    122                         # Strip the header
    123                         msgs = '\n'.join(dropwhile(len, msgs.split('\n')))
    124                     else:
    125                         msgs = msgs.replace('charset=CHARSET', 'charset=UTF-8')
    126                     if msgs:
    127                         open(potfile, 'ab').write(msgs)
    128                     if thefile != file:
    129                         os.unlink(os.path.join(dirpath, thefile))
    130 
    131         if os.path.exists(potfile):
    132             (stdin, stdout, stderr) = os.popen3('msguniq --to-code=utf-8 "%s"' % potfile, 'b')
    133             msgs = stdout.read()
    134             errors = stderr.read()
    135             if errors:
    136                 print "errors happened while running msguniq"
    137                 print errors
    138                 sys.exit(8)
    139             open(potfile, 'w').write(msgs)
    140             if os.path.exists(pofile):
    141                 (stdin, stdout, stderr) = os.popen3('msgmerge -q "%s" "%s"' % (pofile, potfile), 'b')
    142                 msgs = stdout.read()
    143                 errors = stderr.read()
    144                 if errors:
    145                     print "errors happened while running msgmerge"
    146                     print errors
    147                     sys.exit(8)
    148             open(pofile, 'wb').write(msgs)
    149             os.unlink(potfile)
    150 
    15130if __name__ == "__main__":
    152     make_messages()
     31    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"
    4646    # 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"
     47    actions="adminindex createcachetable cleanup dbshell diffsettings \
     48             dumpdata flush inspectdb loaddata messagescompile messagesmake \
     49             messagesunique reset runfcgi runserver shell sql sqlall \
     50             sqlclear sqlcustom sqlflush sqlindexes sqlreset \
     51             sqlsequencereset startapp startproject syncdb test validate"
    5252    # Action's options
    5353    action_shell_opts="--plain"
    5454    action_runfcgi_opts="host port socket method maxspare minspare maxchildren daemonize pidfile workdir"
     
    112112                return 0
    113113                ;;
    114114
    115             createcachetable|dbshell|diffsettings| \
    116             inspectdb|runserver|startapp|startproject|syncdb| \
     115            createcachetable|cleanup|dbshell|diffsettings| \
     116            inspectdb|messagescompile|messagesmake|messagesunique| \
     117            runserver|startapp|startproject|syncdb| \
    117118            validate)
    118119                COMPREPLY=()
    119120                return 0
  • docs/settings.txt

     
    567567        ('en', gettext('English')),
    568568    )
    569569
    570 With this arrangement, ``make-messages.py`` will still find and mark these
    571 strings for translation, but the translation won't happen at runtime -- so
    572 you'll have to remember to wrap the languages in the *real* ``gettext()`` in
     570With this arrangement, ``django-admin messagesmake`` will still find and mark
     571these strings for translation, but the translation won't happen at runtime --
     572so you'll have to remember to wrap the languages in the *real* ``gettext()`` in
    573573any code that uses ``LANGUAGES`` at runtime.
    574574
    575575LOGIN_REDIRECT_URL
  • 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 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::
     
    384384available translation strings and how they should be represented in the given
    385385language. Message files have a ``.po`` file extension.
    386386
    387 Django comes with a tool, ``bin/make-messages.py``, that automates the creation
     387Django comes with a tool, ``django-admin.py messagesmake``, that automates the creation
    388388and upkeep of these files.
    389389
    390390To create or update a message file, run this command::
    391391
    392     bin/make-messages.py -l de
     392    django-admin.py messagesmake -l de
    393393
    394394...where ``de`` is the language code for the message file you want to create.
    395395The language code, in this case, is in locale format. For example, it's
     
    414414
    415415.. admonition:: No gettext?
    416416
    417     If you don't have the ``gettext`` utilities installed, ``make-messages.py``
     417    If you don't have the ``gettext`` utilities installed, ``django-admin.py messagesmake``
    418418    will create empty files. If that's the case, either install the ``gettext``
    419419    utilities or just copy the English message file
    420420    (``conf/locale/en/LC_MESSAGES/django.po``) and use it as a starting point;
     
    431431
    432432    _("Welcome to my site.")
    433433
    434 ...then ``make-messages.py`` will have created a ``.po`` file containing the
     434...then ``django-admin.py messagesmake`` will have created a ``.po`` file containing the
    435435following snippet -- a message::
    436436
    437437    #: path/to/python/module.py:23
     
    464464To reexamine all source code and templates for new translation strings and
    465465update all message files for **all** languages, run this::
    466466
    467     make-messages.py -a
     467    django-admin.py messagesmake -a
    468468
     469Remove duplicate translations strings
     470-------------------------------------
     471
     472Sometimes duplicate translations of the same message ID occur which are invalid
     473for the Django underlying gettext mechanism. This tool merges the duplicates in
     474the current directory recursively::
     475
     476    django-admin.py messagesunique
     477
    469478Compiling message files
    470479-----------------------
    471480
    472481After you create your message file -- and each time you make changes to it --
    473482you'll need to compile it into a more efficient form, for use by ``gettext``.
    474 Do this with the ``bin/compile-messages.py`` utility.
     483Do this with the ``django-admin.py messagescompile`` utility.
    475484
    476485This tool runs over all available ``.po`` files and creates ``.mo`` files,
    477486which are binary files optimized for use by ``gettext``. In the same directory
    478 from which you ran ``make-messages.py``, run ``compile-messages.py`` like
    479 this::
     487from which you ran ``django-admin.py messagesmake``, run ``django-admin.py messagescompile``
     488like this::
    480489
    481    bin/compile-messages.py
     490   django-admin.py messagescompile
    482491
    483492That's it. Your translations are ready for use.
    484493
     
    586595              ('en', ugettext('English')),
    587596          )
    588597
    589       With this arrangement, ``make-messages.py`` will still find and mark
     598      With this arrangement, ``django-admin.py messagesmake`` will still find and mark
    590599      these strings for translation, but the translation won't happen at
    591600      runtime -- so you'll have to remember to wrap the languages in the *real*
    592601      ``ugettext()`` in any code that uses ``LANGUAGES`` at runtime.
     
    703712      searched in that order for ``<language>/LC_MESSAGES/django.(po|mo)``
    704713    * ``$PYTHONPATH/django/conf/locale/<language>/LC_MESSAGES/django.(po|mo)``
    705714
    706 To create message files, you use the same ``make-messages.py`` tool as with the
    707 Django message files. You only need to be in the right place -- in the directory
    708 where either the ``conf/locale`` (in case of the source tree) or the ``locale/``
    709 (in case of app messages or project messages) directory are located. And you
    710 use the same ``compile-messages.py`` to produce the binary ``django.mo`` files that
    711 are used by ``gettext``.
     715To create message files, you use the same ``django-admin.py messagesmake`` tool as
     716with the Django message files. You only need to be in the right place -- in the
     717directory where either the ``conf/locale`` (in case of the source tree) or the
     718``locale/`` (in case of app messages or project messages) directory are located.
     719And you use the same ``django-admin.py messagescompile`` to produce the binary
     720``django.mo`` files that are used by ``gettext``.
    712721
    713722Application message files are a bit complicated to discover -- they need the
    714723``LocaleMiddleware``. If you don't use the middleware, only the Django message
     
    718727files. If your applications need to be delivered to other users and will
    719728be used in other projects, you might want to use app-specific translations.
    720729But using app-specific translations and project translations could produce
    721 weird problems with ``make-messages``: ``make-messages`` will traverse all
     730weird problems with ``messagesmake``: ``messagesmake`` will traverse all
    722731directories below the current path and so might put message IDs into the
    723732project message file that are already in application message files.
    724733
    725734The easiest way out is to store applications that are not part of the project
    726735(and so carry their own translations) outside the project tree. That way,
    727 ``make-messages`` on the project level will only translate strings that are
     736``messagesmake`` on the project level will only translate strings that are
    728737connected to your explicit project and not strings that are distributed
    729738independently.
    730739
     
    818827----------------------------------------
    819828
    820829You create and update the translation catalogs the same way as the other Django
    821 translation catalogs -- with the {{{make-messages.py}}} tool. The only
     830translation catalogs -- with the ``messagesmake`` tool. The only
    822831difference is you need to provide a ``-d djangojs`` parameter, like this::
    823832
    824     make-messages.py -d djangojs -l de
     833    django-admin.py messagesmake -d djangojs -l de
    825834
    826835This would create or update the translation catalog for JavaScript for German.
    827 After updating translation catalogs, just run ``compile-messages.py`` the same
    828 way as you do with normal Django translation catalogs.
     836After updating translation catalogs, just run ``django-admin.py messagescompile``
     837the same way as you do with normal Django translation catalogs.
    829838
    830839Specialities of Django translation
    831840==================================
  • 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
    8894createcachetable <tablename>
    8995----------------------------
    9096
     
    314320
    315321    django-admin.py loaddata --verbosity=2
    316322
     323messagescompile
     324---------------
     325
     326Compiles .po files created with ``messagesmake`` to .mo files for use with
     327the builtin gettext support.
     328
     329.. i18n documentation: ../i18n/#compiling-message-files
     330
     331--locale
     332~~~~~~~~
     333
     334Use the ``--locale`` or ``-l`` option to specify the locale to process.
     335If not provided all locales are processed.
     336
     337Example usage::
     338
     339    django-admin.py messagescompile --locale=br_PT
     340
     341messagesmake
     342------------
     343
     344Runs over the entire source tree of the current directory and pulls out all
     345strings marked for translation. It creates (or updates) a message file in the
     346conf/locale (in the django tree) or locale (for project and application)
     347directory. After making changes to the messages files you need to compile them
     348with ``messagescompile`` for use with the builtin gettext support.
     349
     350.. i18n documentation: ../i18n/#message-files
     351
     352--all
     353~~~~~
     354
     355Use the ``--all`` or ``-a`` option to update the message files for all
     356available languages.
     357
     358Example usage::
     359
     360    django-admin.py messagesmake --all
     361
     362--locale
     363~~~~~~~~
     364
     365Use the ``--locale`` or ``-l`` option to specify the locale to process.
     366
     367Example usage::
     368
     369    django-admin.py messagesmake --locale=br_PT
     370
     371--domain
     372~~~~~~~~
     373
     374Use the ``--domain`` or ``-d`` option to change the domain of the messages files.
     375Currently supported::
     376
     377    * ``django`` for all *.py and *.html files (default)
     378    * ``djangojs`` for *.js files
     379
     380--verbosity
     381~~~~~~~~~~~
     382
     383Use ``--verbosity`` or ``-v`` to specify the amount of notification and debug
     384information that ``django-admin.py`` should print to the console.
     385
     386        * ``0`` means no input.
     387        * ``1`` means normal input (default).
     388        * ``2`` means verbose input.
     389
     390Example usage::
     391
     392    django-admin.py messagesmake --verbosity=2
     393
     394messagesunique
     395--------------
     396
     397Unifies duplicate translations of the same message ID in the messages
     398files created with ``messagesmake``.
     399
    317400reset <appname appname ...>
    318401---------------------------
    319402
     
    505588Creates a Django app directory structure for the given app name in the current
    506589directory.
    507590
Back to Top