Ticket #5522: django-admin.4.diff
File django-admin.4.diff, 36.8 KB (added by , 17 years ago) |
---|
-
django/core/management/commands/makemessages.py
1 import re 2 import os 3 import sys 4 from optparse import make_option 5 from django.core.management.base import CommandError, BaseCommand, make_messages 6 7 pythonize_re = re.compile(r'\n\s*//') 8 9 class Command(BaseCommand): 10 option_list = BaseCommand.option_list + ( 11 make_option('--locale', '-l', default=None, dest='locale', 12 help='Creates or updates the message files only for the given locale (e.g. pt_BR).'), 13 make_option('--domain', '-d', default='django', dest='domain', 14 help='The domain of the message files (default: "django").'), 15 make_option('--verbosity', '-v', action='store', dest='verbosity', 16 default='1', type='choice', choices=['0', '1', '2'], 17 help='Verbosity level; 0=minimal output, 1=normal output, 2=all output'), 18 make_option('--all', '-a', action='store_true', dest='all', 19 default=False, help='Reexamines all source code and templates for new translation strings and updates all message files for all available languages.'), 20 ) 21 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." 22 23 requires_model_validation = False 24 can_import_settings = False 25 26 def handle(self, *args, **options): 27 if len(args) != 0: 28 raise CommandError("Command doesn't accept any arguments") 29 30 locale = options.get('locale') 31 domain = options.get('domain') 32 verbosity = int(options.get('verbosity')) 33 process_all = options.get('all') 34 35 make_messages(locale, domain, verbosity, process_all) -
django/core/management/commands/compilemessages.py
1 import os 2 import sys 3 from optparse import make_option 4 from django.core.management.base import BaseCommand, compile_messages 5 from django.core.management.color import no_style 6 7 try: 8 set 9 except NameError: 10 from sets import Set as set # For Python 2.3 11 12 class Command(BaseCommand): 13 option_list = BaseCommand.option_list + ( 14 make_option('--locale', '-l', dest='locale', 15 help='The locale to process. Default is to process all.'), 16 ) 17 help = 'Compiles .po files to .mo files for use with builtin gettext support.' 18 19 requires_model_validation = False 20 can_import_settings = False 21 22 def handle(self, **options): 23 locale = options.get('locale') 24 compile_messages(locale) -
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
1 1 import os 2 2 import sys 3 from itertools import dropwhile 3 4 from optparse import make_option, OptionParser 4 5 5 6 import django 6 7 from django.core.exceptions import ImproperlyConfigured 7 8 from django.core.management.color import color_style 8 9 10 try: 11 set 12 except NameError: 13 from sets import Set as set # For Python 2.3 14 9 15 class CommandError(Exception): 10 16 pass 11 17 … … 170 176 def handle_noargs(self, **options): 171 177 raise NotImplementedError() 172 178 179 def make_messages(locale=None, domain='django', verbosity='1', all=False): 180 """ 181 Uses the locale directory from the Django SVN tree or an application/ 182 project to process all 183 """ 184 # Need to ensure that the i18n framework is enabled 185 from django.conf import settings 186 settings.configure(USE_I18N = True) 187 188 from django.utils.translation import templatize 189 190 if os.path.isdir(os.path.join('conf', 'locale')): 191 localedir = os.path.abspath(os.path.join('conf', 'locale')) 192 elif os.path.isdir('locale'): 193 localedir = os.path.abspath('locale') 194 else: 195 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.") 196 197 if domain not in ('django', 'djangojs'): 198 raise CommandError("currently makemessages only supports domains 'django' and 'djangojs'") 199 200 if (locale is None and not all) or domain is None: 201 # backwards compatible error message 202 if not sys.argv[0].endswith("make-messages.py"): 203 message = "Type '%s help %s' for usage.\n" % (os.path.basename(sys.argv[0]), sys.argv[1]) 204 else: 205 message = "usage: make-messages.py -l <language>\n or: make-messages.py -a\n" 206 sys.stderr.write(message) 207 sys.exit(1) 208 209 languages = [] 210 if locale is not None: 211 languages.append(locale) 212 elif all: 213 languages = [el for el in os.listdir(localedir) if not el.startswith('.')] 214 215 for locale in languages: 216 if verbosity > 0: 217 print "processing language", locale 218 basedir = os.path.join(localedir, locale, 'LC_MESSAGES') 219 if not os.path.isdir(basedir): 220 os.makedirs(basedir) 221 222 pofile = os.path.join(basedir, '%s.po' % domain) 223 potfile = os.path.join(basedir, '%s.pot' % domain) 224 225 if os.path.exists(potfile): 226 os.unlink(potfile) 227 228 all_files = [] 229 for (dirpath, dirnames, filenames) in os.walk("."): 230 all_files.extend([(dirpath, f) for f in filenames]) 231 all_files.sort() 232 for dirpath, file in all_files: 233 if domain == 'djangojs' and file.endswith('.js'): 234 if verbosity > 1: 235 sys.stdout.write('processing file %s in %s\n' % (file, dirpath)) 236 src = open(os.path.join(dirpath, file), "rb").read() 237 src = pythonize_re.sub('\n#', src) 238 open(os.path.join(dirpath, '%s.py' % file), "wb").write(src) 239 thefile = '%s.py' % file 240 cmd = 'xgettext %s -d %s -L Perl --keyword=gettext_noop --keyword=gettext_lazy --keyword=ngettext_lazy:1,2 --from-code UTF-8 -o - "%s"' % ( 241 os.path.exists(potfile) and '--omit-header' or '', domain, os.path.join(dirpath, thefile)) 242 (stdin, stdout, stderr) = os.popen3(cmd, 't') 243 msgs = stdout.read() 244 errors = stderr.read() 245 if errors: 246 print "errors happened while running xgettext on %s" % file 247 print errors 248 sys.exit(8) 249 old = '#: '+os.path.join(dirpath, thefile)[2:] 250 new = '#: '+os.path.join(dirpath, file)[2:] 251 msgs = msgs.replace(old, new) 252 if msgs: 253 open(potfile, 'ab').write(msgs) 254 os.unlink(os.path.join(dirpath, thefile)) 255 elif domain == 'django' and (file.endswith('.py') or file.endswith('.html')): 256 thefile = file 257 if file.endswith('.html'): 258 src = open(os.path.join(dirpath, file), "rb").read() 259 thefile = '%s.py' % file 260 open(os.path.join(dirpath, thefile), "wb").write(templatize(src)) 261 if verbosity > 1: 262 sys.stdout.write('processing file %s in %s\n' % (file, dirpath)) 263 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"' % ( 264 domain, os.path.join(dirpath, thefile)) 265 (stdin, stdout, stderr) = os.popen3(cmd, 't') 266 msgs = stdout.read() 267 errors = stderr.read() 268 if errors: 269 print "errors happened while running xgettext on %s" % file 270 print errors 271 sys.exit(8) 272 if thefile != file: 273 old = '#: '+os.path.join(dirpath, thefile)[2:] 274 new = '#: '+os.path.join(dirpath, file)[2:] 275 msgs = msgs.replace(old, new) 276 if os.path.exists(potfile): 277 # Strip the header 278 msgs = '\n'.join(dropwhile(len, msgs.split('\n'))) 279 else: 280 msgs = msgs.replace('charset=CHARSET', 'charset=UTF-8') 281 if msgs: 282 open(potfile, 'ab').write(msgs) 283 if thefile != file: 284 os.unlink(os.path.join(dirpath, thefile)) 285 286 if os.path.exists(potfile): 287 (stdin, stdout, stderr) = os.popen3('msguniq --to-code=utf-8 "%s"' % potfile, 'b') 288 msgs = stdout.read() 289 errors = stderr.read() 290 if errors: 291 print "errors happened while running msguniq" 292 print errors 293 sys.exit(8) 294 open(potfile, 'w').write(msgs) 295 if os.path.exists(pofile): 296 (stdin, stdout, stderr) = os.popen3('msgmerge -q "%s" "%s"' % (pofile, potfile), 'b') 297 msgs = stdout.read() 298 errors = stderr.read() 299 if errors: 300 print "errors happened while running msgmerge" 301 print errors 302 sys.exit(8) 303 open(pofile, 'wb').write(msgs) 304 os.unlink(potfile) 305 306 def compile_messages(locale=None): 307 basedirs = (os.path.join('conf', 'locale'), 'locale') 308 if os.environ.get('DJANGO_SETTINGS_MODULE'): 309 from django.conf import settings 310 basedirs += settings.LOCALE_PATHS 311 312 # Gather existing directories. 313 basedirs = set(map(os.path.abspath, filter(os.path.isdir, basedirs))) 314 315 if not basedirs: 316 raise CommandError("This script should be run from the Django SVN tree or your project or app tree, or with the settings module specified.") 317 318 for basedir in basedirs: 319 if locale: 320 basedir = os.path.join(basedir, locale, 'LC_MESSAGES') 321 for dirpath, dirnames, filenames in os.walk(basedir): 322 for f in filenames: 323 if f.endswith('.po'): 324 sys.stderr.write('processing file %s in %s\n' % (f, dirpath)) 325 pf = os.path.splitext(os.path.join(dirpath, f))[0] 326 # Store the names of the .mo and .po files in an environment 327 # variable, rather than doing a string replacement into the 328 # command, so that we can take advantage of shell quoting, to 329 # quote any malicious characters/escaping. 330 # See http://cyberelk.net/tim/articles/cmdline/ar01s02.html 331 os.environ['djangocompilemo'] = pf + '.mo' 332 os.environ['djangocompilepo'] = pf + '.po' 333 if sys.platform == 'win32': # Different shell-variable syntax 334 cmd = 'msgfmt --check-format -o "%djangocompilemo%" "%djangocompilepo%"' 335 else: 336 cmd = 'msgfmt --check-format -o "$djangocompilemo" "$djangocompilepo"' 337 os.system(cmd) 338 173 339 def copy_helper(style, app_or_project, name, directory, other_name=''): 174 340 """ 175 341 Copies either a Django application layout template or a Django project -
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/compile-messages.py
1 1 #!/usr/bin/env python 2 2 3 import optparse4 3 import os 5 import sys 4 import optparse 5 from django.core.management.base import compile_messages 6 6 7 try:8 set9 except NameError:10 from sets import Set as set # For Python 2.311 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 settings17 basedirs += settings.LOCALE_PATHS18 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 environment38 # variable, rather than doing a string replacement into the39 # command, so that we can take advantage of shell quoting, to40 # quote any malicious characters/escaping.41 # See http://cyberelk.net/tim/articles/cmdline/ar01s02.html42 os.environ['djangocompilemo'] = pf + '.mo'43 os.environ['djangocompilepo'] = pf + '.po'44 if sys.platform == 'win32': # Different shell-variable syntax45 cmd = 'msgfmt --check-format -o "%djangocompilemo%" "%djangocompilepo%"'46 else:47 cmd = 'msgfmt --check-format -o "$djangocompilemo" "$djangocompilepo"'48 os.system(cmd)49 50 7 def main(): 51 8 parser = optparse.OptionParser() 52 9 parser.add_option('-l', '--locale', dest='locale', -
django/bin/make-messages.py
1 1 #!/usr/bin/env python 2 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 3 import os 10 import sys 11 import getopt 12 from itertools import dropwhile 4 import optparse 5 from django.core.management.base import make_messages 13 6 14 pythonize_re = re.compile(r'\n\s*//') 7 def 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.') 15 20 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 23 26 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) 31 31 32 (opts, args) = getopt.getopt(sys.argv[1:], 'l:d:va')33 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 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' % file88 cmd = 'xgettext %s -d %s -L Perl --keyword=gettext_noop --keyword=gettext_lazy --keyword=ngettext_lazy:1,2 --from-code UTF-8 -o - "%s"' % (89 os.path.exists(potfile) and '--omit-header' or '', domain, os.path.join(dirpath, thefile))90 (stdin, stdout, stderr) = os.popen3(cmd, 't')91 msgs = stdout.read()92 errors = stderr.read()93 if errors:94 print "errors happened while running xgettext on %s" % file95 print errors96 sys.exit(8)97 old = '#: '+os.path.join(dirpath, thefile)[2:]98 new = '#: '+os.path.join(dirpath, file)[2:]99 msgs = msgs.replace(old, new)100 if msgs:101 open(potfile, 'ab').write(msgs)102 os.unlink(os.path.join(dirpath, thefile))103 elif domain == 'django' and (file.endswith('.py') or file.endswith('.html')):104 thefile = file105 if file.endswith('.html'):106 src = open(os.path.join(dirpath, file), "rb").read()107 thefile = '%s.py' % file108 open(os.path.join(dirpath, thefile), "wb").write(templatize(src))109 if verbose:110 sys.stdout.write('processing file %s in %s\n' % (file, dirpath))111 cmd = 'xgettext -d %s -L Python --keyword=gettext_noop --keyword=gettext_lazy --keyword=ngettext_lazy:1,2 --keyword=ugettext_noop --keyword=ugettext_lazy --keyword=ungettext_lazy:1,2 --from-code UTF-8 -o - "%s"' % (112 domain, os.path.join(dirpath, thefile))113 (stdin, stdout, stderr) = os.popen3(cmd, 't')114 msgs = stdout.read()115 errors = stderr.read()116 if errors:117 print "errors happened while running xgettext on %s" % file118 print errors119 sys.exit(8)120 if thefile != file:121 old = '#: '+os.path.join(dirpath, thefile)[2:]122 new = '#: '+os.path.join(dirpath, file)[2:]123 msgs = msgs.replace(old, new)124 if os.path.exists(potfile):125 # Strip the header126 msgs = '\n'.join(dropwhile(len, msgs.split('\n')))127 else:128 msgs = msgs.replace('charset=CHARSET', 'charset=UTF-8')129 if msgs:130 open(potfile, 'ab').write(msgs)131 if thefile != file:132 os.unlink(os.path.join(dirpath, thefile))133 134 if os.path.exists(potfile):135 (stdin, stdout, stderr) = os.popen3('msguniq --to-code=utf-8 "%s"' % potfile, 'b')136 msgs = stdout.read()137 errors = stderr.read()138 if errors:139 print "errors happened while running msguniq"140 print errors141 sys.exit(8)142 open(potfile, 'w').write(msgs)143 if os.path.exists(pofile):144 (stdin, stdout, stderr) = os.popen3('msgmerge -q "%s" "%s"' % (pofile, potfile), 'b')145 msgs = stdout.read()146 errors = stderr.read()147 if errors:148 print "errors happened while running msgmerge"149 print errors150 sys.exit(8)151 open(pofile, 'wb').write(msgs)152 os.unlink(potfile)153 154 32 if __name__ == "__main__": 155 ma ke_messages()33 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 47 # 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 52 54 # Action's options 53 55 action_shell_opts="--plain" 54 56 action_runfcgi_opts="host port socket method maxspare minspare maxchildren daemonize pidfile workdir" … … 112 114 return 0 113 115 ;; 114 116 115 createcachetable|dbshell|diffsettings| \ 116 inspectdb|runserver|startapp|startproject|syncdb| \ 117 createcachetable|cleanup|compilemessages|dbshell| \ 118 diffsettings|inspectdb|makemessages| \ 119 runserver|startapp|startproject|syncdb| \ 117 120 validate) 118 121 COMPREPLY=() 119 122 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" "" 2 2 .SH "NAME" 3 3 django\-admin.py \- Utility script for the Django web framework 4 4 .SH "SYNOPSIS" … … 21 21 .BI "adminindex [" "appname ..." "]" 22 22 Prints the admin\-index template snippet for the given app name(s). 23 23 .TP 24 .BI cleanup 25 Cleans out old data from the database (only expired sessions at the moment). 26 .TP 27 .BI "compilemessages [" "\-\-locale=LOCALE" "]" 28 Compiles .po files to .mo files for use with builtin gettext support. 29 .TP 24 30 .BI "createcachetable [" "tablename" "]" 25 31 Creates the table needed to use the SQL cache backend 26 32 .TP … … 43 49 .B sqlall 44 50 for the given app(s) in the current database. 45 51 .TP 52 .BI "makemessages [" "\-\-locale=LOCALE" "] [" "\-\-domain=DOMAIN" "] [" "\-\-all" "]" 53 Runs over the entire source tree of the current directory and pulls out all 54 strings marked for translation. It creates (or updates) a message file in the 55 conf/locale (in the django tree) or locale (for project and application) directory. 56 .TP 46 57 .BI "reset [" "appname ..." "]" 47 58 Executes 48 59 .B sqlreset … … 136 147 .TP 137 148 .I \-\-adminmedia=ADMIN_MEDIA_PATH 138 149 Specifies the directory from which to serve admin media when using the development server. 139 150 .TP 151 .I \-l, \-\-locale=LOCALE 152 The locale to process when using makemessages or compilemessages. 153 .TP 154 .I \-d, \-\-domain=DOMAIN 155 The domain of the message files (default: "django") when using makemessages. 156 .TP 157 .I \-a, \-\-all 158 Process all available locales when using makemessages. 140 159 .SH "ENVIRONMENT" 141 160 .TP 142 161 .I DJANGO_SETTINGS_MODULE -
docs/settings.txt
625 625 ('en', gettext('English')), 626 626 ) 627 627 628 With this arrangement, `` make-messages.py`` will still find and mark these629 strings for translation, but the translation won't happen at runtime -- so 630 you'll have to remember to wrap the languages in the *real* ``gettext()`` in 631 any code that uses ``LANGUAGES`` at runtime.628 With this arrangement, ``django-admin.py makemessages`` will still find and 629 mark these strings for translation, but the translation won't happen at 630 runtime -- so you'll have to remember to wrap the languages in the *real* 631 ``gettext()`` in any code that uses ``LANGUAGES`` at runtime. 632 632 633 633 LOCALE_PATHS 634 634 ------------ -
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 ``make -messages`` later.)125 ``django-admin.py makemessages``, won't be able to find these strings. More on 126 ``makemessages`` 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:: … … 392 392 available translation strings and how they should be represented in the given 393 393 language. Message files have a ``.po`` file extension. 394 394 395 Django comes with a tool, `` bin/make-messages.py``, that automates the creation396 and upkeep of these files.395 Django comes with a tool, ``django-admin.py makemessages``, that automates the 396 creation and upkeep of these files. 397 397 398 398 To create or update a message file, run this command:: 399 399 400 bin/make-messages.py-l de400 django-admin.py makemessages -l de 401 401 402 402 ...where ``de`` is the language code for the message file you want to create. 403 403 The language code, in this case, is in locale format. For example, it's … … 422 422 423 423 .. admonition:: No gettext? 424 424 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 file428 (``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. 430 430 431 431 The format of ``.po`` files is straightforward. Each ``.po`` file contains a 432 432 small bit of metadata, such as the translation maintainer's contact … … 439 439 440 440 _("Welcome to my site.") 441 441 442 ...then `` make-messages.py`` will have created a ``.po`` file containing the443 following snippet -- a message::442 ...then ``django-admin.py makemessages`` will have created a ``.po`` file 443 containing the following snippet -- a message:: 444 444 445 445 #: path/to/python/module.py:23 446 446 msgid "Welcome to my site." … … 475 475 To reexamine all source code and templates for new translation strings and 476 476 update all message files for **all** languages, run this:: 477 477 478 make-messages.py-a478 django-admin.py makemessages -a 479 479 480 480 Compiling message files 481 481 ----------------------- … … 486 486 487 487 This tool runs over all available ``.po`` files and creates ``.mo`` files, 488 488 which are binary files optimized for use by ``gettext``. In the same directory 489 from which you ran `` make-messages.py``, run ``compile-messages.py`` like489 from which you ran ``django-admin.py makemessages``, run ``compile-messages.py`` like 490 490 this:: 491 491 492 492 bin/compile-messages.py … … 597 597 ('en', ugettext('English')), 598 598 ) 599 599 600 With this arrangement, `` make-messages.py`` will still find and mark601 these strings for translation, but the translation won't happen at602 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* 603 603 ``ugettext()`` in any code that uses ``LANGUAGES`` at runtime. 604 604 605 605 * The ``LocaleMiddleware`` can only select languages for which there is a … … 676 676 searched in that order for ``<language>/LC_MESSAGES/django.(po|mo)`` 677 677 * ``$PYTHONPATH/django/conf/locale/<language>/LC_MESSAGES/django.(po|mo)`` 678 678 679 To create message files, you use the same `` make-messages.py`` tool as with the680 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 th at are used by ``gettext``.679 To create message files, you use the same ``django-admin.py makemessages`` 680 tool 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 682 tree) or the ``locale/`` (in case of app messages or project messages) 683 directory are located. And you use the same ``compile-messages.py`` to produce 684 the binary ``django.mo`` files that are used by ``gettext``. 685 685 686 686 You can also run ``compile-message.py --settings=path.to.settings`` to make 687 687 the compiler process all the directories in your ``LOCALE_PATHS`` setting. … … 694 694 files. If your applications need to be delivered to other users and will 695 695 be used in other projects, you might want to use app-specific translations. 696 696 But using app-specific translations and project translations could produce 697 weird problems with ``make -messages``: ``make-messages`` will traverse all697 weird problems with ``makemessages``: ``makemessages`` will traverse all 698 698 directories below the current path and so might put message IDs into the 699 699 project message file that are already in application message files. 700 700 701 701 The easiest way out is to store applications that are not part of the project 702 702 (and so carry their own translations) outside the project tree. That way, 703 `` make-messages`` on the project level will only translate strings that are704 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 704 strings that are connected to your explicit project and not strings that are 705 distributed independently. 706 706 707 707 The ``set_language`` redirect view 708 708 ================================== … … 834 834 ---------------------------------------- 835 835 836 836 You create and update the translation catalogs the same way as the other 837 Django translation catalogs -- with the make-messages.py tool. The only838 difference is you need to provide a ``-d djangojs`` parameter, like this::837 Django translation catalogs -- with the django-admin.py makemessages tool. The 838 only difference is you need to provide a ``-d djangojs`` parameter, like this:: 839 839 840 make-messages.py-d djangojs -l de840 django-admin.py makemessages -d djangojs -l de 841 841 842 842 This would create or update the translation catalog for JavaScript for German. 843 843 After updating translation catalogs, just run ``compile-messages.py`` the same -
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 94 compilemessages 95 --------------- 96 97 Compiles .po files created with ``makemessages`` to .mo files for use with 98 the builtin gettext support. See the `i18n documentation`_ for details. 99 100 --locale 101 ~~~~~~~~ 102 103 Use the ``--locale`` or ``-l`` option to specify the locale to process. 104 If not provided all locales are processed. 105 106 Example usage:: 107 108 django-admin.py compilemessages --locale=br_PT 109 88 110 createcachetable <tablename> 89 111 ---------------------------- 90 112 … … 321 343 322 344 django-admin.py loaddata --verbosity=2 323 345 346 makemessages 347 ------------ 348 349 Runs over the entire source tree of the current directory and pulls out all 350 strings marked for translation. It creates (or updates) a message file in the 351 conf/locale (in the django tree) or locale (for project and application) 352 directory. After making changes to the messages files you need to compile them 353 with ``compilemessages`` for use with the builtin gettext support. See the 354 `i18n documentation`_ for details. 355 356 .. _i18n documentation: ../i18n/#how-to-create-language-files 357 358 --all 359 ~~~~~ 360 361 Use the ``--all`` or ``-a`` option to update the message files for all 362 available languages. 363 364 Example usage:: 365 366 django-admin.py makemessages --all 367 368 --locale 369 ~~~~~~~~ 370 371 Use the ``--locale`` or ``-l`` option to specify the locale to process. 372 373 Example usage:: 374 375 django-admin.py makemessages --locale=br_PT 376 377 --domain 378 ~~~~~~~~ 379 380 Use the ``--domain`` or ``-d`` option to change the domain of the messages files. 381 Currently supported: 382 383 * ``django`` for all ``*.py`` and ``*.html`` files (default) 384 * ``djangojs`` for ``*.js`` files 385 386 --verbosity 387 ~~~~~~~~~~~ 388 389 Use ``--verbosity`` or ``-v`` to specify the amount of notification and debug 390 information that ``django-admin.py`` should print to the console. 391 392 * ``0`` means no input. 393 * ``1`` means normal input (default). 394 * ``2`` means verbose input. 395 396 Example usage:: 397 398 django-admin.py makemessages --verbosity=2 399 324 400 reset <appname appname ...> 325 401 --------------------------- 326 402