Ticket #5522: django-admin.diff
File django-admin.diff, 37.2 KB (added by , 17 years ago) |
---|
-
django/core/management/commands/messagesunique.py
1 import os 2 import sys 3 from django.core.management.base import BaseCommand, CommandError, get_locale_dir 4 5 class 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
1 import re 2 import os 3 import sys 4 from itertools import dropwhile 5 from optparse import make_option 6 from django.core.management.base import CommandError, BaseCommand, get_locale_dir 7 from django.utils.translation import templatize 8 9 # Need to ensure that the i18n framework is enabled 10 from django.conf import settings 11 settings.configure(USE_I18N = True) 12 13 pythonize_re = re.compile(r'\n\s*//') 14 15 class 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 2 import os 3 import sys 4 from optparse import make_option 5 from django.core.management.base import BaseCommand, CommandError, get_locale_dir 6 from django.core.management.color import no_style 7 8 class 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
1 import datetime 2 from django.core.management.base import NoArgsCommand 3 4 class 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
203 203 except OSError: 204 204 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)) 205 205 206 def 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 206 216 def _make_writeable(filename): 207 217 "Makes sure that the file is writeable. Useful if our source is read-only." 208 218 import stat -
django/bin/daily_cleanup.py
7 7 sessions at the moment). 8 8 """ 9 9 10 import datetime 11 from django.db import transaction 12 from django.contrib.sessions.models import Session 10 from django.core import management 13 11 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 19 12 if __name__ == "__main__": 20 clean_up()13 management.call_command('cleanup') -
django/bin/unique-messages.py
1 1 #!/usr/bin/env python 2 from django.core import management 2 3 3 import os4 import sys5 6 def unique_messages():7 basedir = None8 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"' % pf23 stdout = os.popen(cmd)24 msg = stdout.read()25 open('%s.po' % pf, 'w').write(msg)26 27 4 if __name__ == "__main__": 28 unique_messages()5 management.call_command('messagesunique') -
django/bin/compile-messages.py
1 1 #!/usr/bin/env python 2 3 import optparse4 2 import os 5 3 import sys 4 import optparse 5 from django.core import management 6 6 7 def compile_messages(locale=None):8 basedir = None9 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 environment27 # variable, rather than doing a string replacement into the28 # command, so that we can take advantage of shell quoting, to29 # quote any malicious characters/escaping.30 # See http://cyberelk.net/tim/articles/cmdline/ar01s02.html31 os.environ['djangocompilemo'] = pf + '.mo'32 os.environ['djangocompilepo'] = pf + '.po'33 if sys.platform == 'win32': # Different shell-variable syntax34 cmd = 'msgfmt --check-format -o "%djangocompilemo%" "%djangocompilepo%"'35 else:36 cmd = 'msgfmt --check-format -o "$djangocompilemo" "$djangocompilepo"'37 os.system(cmd)38 39 7 def main(): 40 8 parser = optparse.OptionParser() 41 9 parser.add_option('-l', '--locale', dest='locale', 42 10 help="The locale to process. Default is to process all.") 43 11 options, args = parser.parse_args() 44 12 if len(args): 45 13 parser.error("This program takes no arguments") 46 compile_messages(options.locale)14 management.call_command('messagescompile', locale=options.locale) 47 15 48 16 if __name__ == "__main__": 49 17 main() -
django/bin/make-messages.py
1 1 #!/usr/bin/env python 2 3 # Need to ensure that the i18n framework is enabled4 from django.conf import settings5 settings.configure(USE_I18N = True)6 7 from django.utils.translation import templatize8 import re9 2 import os 10 3 import sys 11 4 import getopt 12 from itertools import dropwhile 5 import optparse 6 from django.core import management 13 7 14 pythonize_re = re.compile(r'\n\s*//') 8 def 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.') 15 18 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 23 24 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 31 26 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) 33 29 34 lang = None35 domain = 'django'36 verbose = False37 all = False38 39 for o, v in opts:40 if o == '-l':41 lang = v42 elif o == '-d':43 domain = v44 elif o == '-v':45 verbose = True46 elif o == '-a':47 all = True48 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", lang67 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' % file85 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" % file92 print errors93 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 = file102 if file.endswith('.html'):103 src = open(os.path.join(dirpath, file), "rb").read()104 thefile = '%s.py' % file105 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" % file115 print errors116 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 header123 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 errors138 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 errors147 sys.exit(8)148 open(pofile, 'wb').write(msgs)149 os.unlink(potfile)150 151 30 if __name__ == "__main__": 152 ma ke_messages()31 main() -
extras/django_bash_completion
42 42 prev="${COMP_WORDS[COMP_CWORD-1]}" 43 43 44 44 # 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 46 # Actions 47 actions="adminindex createcachetable dbshell diffsettings \48 dumpdata flush inspectdb loaddata reset runfcgi runserver\49 shell sql sqlall sqlclear sqlcustom sqlflush sqlindexes\50 sql reset sqlsequencereset startapp startproject \51 s yncdb 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" 52 52 # Action's options 53 53 action_shell_opts="--plain" 54 54 action_runfcgi_opts="host port socket method maxspare minspare maxchildren daemonize pidfile workdir" … … 112 112 return 0 113 113 ;; 114 114 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| \ 117 118 validate) 118 119 COMPREPLY=() 119 120 return 0 -
docs/settings.txt
567 567 ('en', gettext('English')), 568 568 ) 569 569 570 With this arrangement, `` make-messages.py`` will still find and mark these571 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()`` in570 With this arrangement, ``django-admin messagesmake`` will still find and mark 571 these strings for translation, but the translation won't happen at runtime -- 572 so you'll have to remember to wrap the languages in the *real* ``gettext()`` in 573 573 any code that uses ``LANGUAGES`` at runtime. 574 574 575 575 LOGIN_REDIRECT_URL -
docs/i18n.txt
122 122 123 123 (The caveat with using variables or computed values, as in the previous two 124 124 examples, is that Django's translation-string-detecting utility, 125 `` make-messages.py``, won't be able to find these strings. More on126 ``m ake-messages`` later.)125 ``django-admin.py messagesmake``, won't be able to find these strings. More on 126 ``messagesmake`` later.) 127 127 128 128 The strings you pass to ``_()`` or ``ugettext()`` can take placeholders, 129 129 specified with Python's standard named-string interpolation syntax. Example:: … … 384 384 available translation strings and how they should be represented in the given 385 385 language. Message files have a ``.po`` file extension. 386 386 387 Django comes with a tool, `` bin/make-messages.py``, that automates the creation387 Django comes with a tool, ``django-admin.py messagesmake``, that automates the creation 388 388 and upkeep of these files. 389 389 390 390 To create or update a message file, run this command:: 391 391 392 bin/make-messages.py-l de392 django-admin.py messagesmake -l de 393 393 394 394 ...where ``de`` is the language code for the message file you want to create. 395 395 The language code, in this case, is in locale format. For example, it's … … 414 414 415 415 .. admonition:: No gettext? 416 416 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`` 418 418 will create empty files. If that's the case, either install the ``gettext`` 419 419 utilities or just copy the English message file 420 420 (``conf/locale/en/LC_MESSAGES/django.po``) and use it as a starting point; … … 431 431 432 432 _("Welcome to my site.") 433 433 434 ...then `` make-messages.py`` will have created a ``.po`` file containing the434 ...then ``django-admin.py messagesmake`` will have created a ``.po`` file containing the 435 435 following snippet -- a message:: 436 436 437 437 #: path/to/python/module.py:23 … … 464 464 To reexamine all source code and templates for new translation strings and 465 465 update all message files for **all** languages, run this:: 466 466 467 make-messages.py-a467 django-admin.py messagesmake -a 468 468 469 Remove duplicate translations strings 470 ------------------------------------- 471 472 Sometimes duplicate translations of the same message ID occur which are invalid 473 for the Django underlying gettext mechanism. This tool merges the duplicates in 474 the current directory recursively:: 475 476 django-admin.py messagesunique 477 469 478 Compiling message files 470 479 ----------------------- 471 480 472 481 After you create your message file -- and each time you make changes to it -- 473 482 you'll need to compile it into a more efficient form, for use by ``gettext``. 474 Do this with the `` bin/compile-messages.py`` utility.483 Do this with the ``django-admin.py messagescompile`` utility. 475 484 476 485 This tool runs over all available ``.po`` files and creates ``.mo`` files, 477 486 which are binary files optimized for use by ``gettext``. In the same directory 478 from which you ran `` make-messages.py``, run ``compile-messages.py`` like479 this::487 from which you ran ``django-admin.py messagesmake``, run ``django-admin.py messagescompile`` 488 like this:: 480 489 481 bin/compile-messages.py490 django-admin.py messagescompile 482 491 483 492 That's it. Your translations are ready for use. 484 493 … … 586 595 ('en', ugettext('English')), 587 596 ) 588 597 589 With this arrangement, `` make-messages.py`` will still find and mark598 With this arrangement, ``django-admin.py messagesmake`` will still find and mark 590 599 these strings for translation, but the translation won't happen at 591 600 runtime -- so you'll have to remember to wrap the languages in the *real* 592 601 ``ugettext()`` in any code that uses ``LANGUAGES`` at runtime. … … 703 712 searched in that order for ``<language>/LC_MESSAGES/django.(po|mo)`` 704 713 * ``$PYTHONPATH/django/conf/locale/<language>/LC_MESSAGES/django.(po|mo)`` 705 714 706 To create message files, you use the same `` make-messages.py`` tool as with the707 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``.715 To create message files, you use the same ``django-admin.py messagesmake`` tool as 716 with the Django message files. You only need to be in the right place -- in the 717 directory 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. 719 And you use the same ``django-admin.py messagescompile`` to produce the binary 720 ``django.mo`` files that are used by ``gettext``. 712 721 713 722 Application message files are a bit complicated to discover -- they need the 714 723 ``LocaleMiddleware``. If you don't use the middleware, only the Django message … … 718 727 files. If your applications need to be delivered to other users and will 719 728 be used in other projects, you might want to use app-specific translations. 720 729 But using app-specific translations and project translations could produce 721 weird problems with ``m ake-messages``: ``make-messages`` will traverse all730 weird problems with ``messagesmake``: ``messagesmake`` will traverse all 722 731 directories below the current path and so might put message IDs into the 723 732 project message file that are already in application message files. 724 733 725 734 The easiest way out is to store applications that are not part of the project 726 735 (and so carry their own translations) outside the project tree. That way, 727 ``m ake-messages`` on the project level will only translate strings that are736 ``messagesmake`` on the project level will only translate strings that are 728 737 connected to your explicit project and not strings that are distributed 729 738 independently. 730 739 … … 818 827 ---------------------------------------- 819 828 820 829 You create and update the translation catalogs the same way as the other Django 821 translation catalogs -- with the {{{make-messages.py}}}tool. The only830 translation catalogs -- with the ``messagesmake`` tool. The only 822 831 difference is you need to provide a ``-d djangojs`` parameter, like this:: 823 832 824 make-messages.py-d djangojs -l de833 django-admin.py messagesmake -d djangojs -l de 825 834 826 835 This would create or update the translation catalog for JavaScript for German. 827 After updating translation catalogs, just run `` compile-messages.py`` the same828 way as you do with normal Django translation catalogs.836 After updating translation catalogs, just run ``django-admin.py messagescompile`` 837 the same way as you do with normal Django translation catalogs. 829 838 830 839 Specialities of Django translation 831 840 ================================== -
docs/django-admin.txt
85 85 86 86 .. _Tutorial 2: ../tutorial02/ 87 87 88 cleanup 89 ------- 90 91 Can be run as a cronjob or directly to clean out old data from the database 92 (only expired sessions at the moment). 93 88 94 createcachetable <tablename> 89 95 ---------------------------- 90 96 … … 314 320 315 321 django-admin.py loaddata --verbosity=2 316 322 323 messagescompile 324 --------------- 325 326 Compiles .po files created with ``messagesmake`` to .mo files for use with 327 the builtin gettext support. 328 329 .. i18n documentation: ../i18n/#compiling-message-files 330 331 --locale 332 ~~~~~~~~ 333 334 Use the ``--locale`` or ``-l`` option to specify the locale to process. 335 If not provided all locales are processed. 336 337 Example usage:: 338 339 django-admin.py messagescompile --locale=br_PT 340 341 messagesmake 342 ------------ 343 344 Runs over the entire source tree of the current directory and pulls out all 345 strings marked for translation. It creates (or updates) a message file in the 346 conf/locale (in the django tree) or locale (for project and application) 347 directory. After making changes to the messages files you need to compile them 348 with ``messagescompile`` for use with the builtin gettext support. 349 350 .. i18n documentation: ../i18n/#message-files 351 352 --all 353 ~~~~~ 354 355 Use the ``--all`` or ``-a`` option to update the message files for all 356 available languages. 357 358 Example usage:: 359 360 django-admin.py messagesmake --all 361 362 --locale 363 ~~~~~~~~ 364 365 Use the ``--locale`` or ``-l`` option to specify the locale to process. 366 367 Example usage:: 368 369 django-admin.py messagesmake --locale=br_PT 370 371 --domain 372 ~~~~~~~~ 373 374 Use the ``--domain`` or ``-d`` option to change the domain of the messages files. 375 Currently supported:: 376 377 * ``django`` for all *.py and *.html files (default) 378 * ``djangojs`` for *.js files 379 380 --verbosity 381 ~~~~~~~~~~~ 382 383 Use ``--verbosity`` or ``-v`` to specify the amount of notification and debug 384 information 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 390 Example usage:: 391 392 django-admin.py messagesmake --verbosity=2 393 394 messagesunique 395 -------------- 396 397 Unifies duplicate translations of the same message ID in the messages 398 files created with ``messagesmake``. 399 317 400 reset <appname appname ...> 318 401 --------------------------- 319 402 … … 505 588 Creates a Django app directory structure for the given app name in the current 506 589 directory. 507 590