Ticket #5463: t5463-r7720.diff
File t5463-r7720.diff, 8.9 KB (added by , 16 years ago) |
---|
-
django/bin/make-messages.py
diff -r 81d089f1a551 django/bin/make-messages.py
a b 5 5 import optparse 6 6 7 7 from django.core.management.base import CommandError 8 from django.core.management.commands.makemessages import make_messages 8 from django.core.management.commands.makemessages import make_messages, handle_extensions 9 9 from django.core.management.color import color_style 10 10 11 11 def main(): … … 18 18 parser.add_option('-v', '--verbose', action='store_true', dest='verbose', 19 19 default=False, help='Verbosity output') 20 20 parser.add_option('-a', '--all', action='store_true', dest='all', 21 default=False, help='Reexamines all source code and templates for \ 22 new translation strings and updates all message files for all \ 23 available languages.') 21 default=False, help='Reexamines all source code and templates for ' 22 'new translation strings and updates all message files for all ' 23 'available languages.') 24 parser.add_option('-e', '--extension', action='append', dest='extensions', 25 help='The file extension(s) to examine (default: ".html", ' 26 'separate multiple extensions with commas, or use -e multiple ' 27 'times).') 24 28 25 29 options, args = parser.parse_args() 26 30 if len(args): … … 29 33 verbosity = 2 30 34 else: 31 35 verbosity = 1 32 36 if options.extensions is None: 37 options.extensions = [] 38 39 extensions = handle_extensions(options.extensions) 33 40 try: 34 41 make_messages(locale=options.locale, domain=options.domain, 35 verbosity=verbosity, all=options.all )42 verbosity=verbosity, all=options.all, extensions=extensions) 36 43 except CommandError, e: 37 44 style = color_style() 38 45 sys.stderr.write(style.ERROR(str('Error: %s\n' % e))) -
django/core/management/commands/makemessages.py
diff -r 81d089f1a551 django/core/management/commands/makemessages.py
a b 5 5 from optparse import make_option 6 6 from django.core.management.base import CommandError, BaseCommand 7 7 8 try: 9 set 10 except NameError: 11 from sets import Set as set # For Python 2.3 12 8 13 pythonize_re = re.compile(r'\n\s*//') 9 14 10 def make_messages(locale=None, domain='django', verbosity='1', all=False): 15 def handle_extensions(extensions, default='.html'): 16 """ 17 organizes multiple extensions that are separated with commas or passed by 18 using --extension/-e multiple times. 19 20 for example: running 'django-admin makemessages -e js,txt -e xhtml -a' 21 would result in a extension list: ['.js', '.txt', '.xhtml'] 22 23 >>> handle_extensions(['.html', 'html,js,py,py,py,.py', 'py,.py']) 24 ['.html', '.js'] 25 """ 26 ext_list = [] 27 for ext in extensions: 28 ext_list += ext.lower().split(',') 29 for i, ext in enumerate(ext_list): 30 if not ext.startswith('.'): 31 ext_list[i] = '.%s' % ext_list[i] 32 33 # we don't want *.py files here because of the way non-*.py files 34 # are handled in make_messages() (they are copied to file.ext.py files to 35 # trick xgettext to parse them as python files) 36 extensions = list(set([x for x in ext_list if not x == ('.py')])) 37 if not extensions: 38 return [default] 39 return extensions 40 41 def make_messages(locale=None, domain='django', verbosity='1', all=False, extensions=None): 11 42 """ 12 43 Uses the locale directory from the Django SVN tree or an application/ 13 project to process all 44 project to process all 14 45 """ 15 46 # Need to ensure that the i18n framework is enabled 16 47 from django.conf import settings 17 48 settings.configure(USE_I18N = True) 18 49 19 50 from django.utils.translation import templatize 20 51 21 52 if os.path.isdir(os.path.join('conf', 'locale')): … … 24 55 localedir = os.path.abspath('locale') 25 56 else: 26 57 raise CommandError("This script should be run from the Django SVN tree or your project or app tree. If you did indeed run it from the SVN checkout or your project or application, maybe you are just missing the conf/locale (in the django tree) or locale (for project and application) directory? It is not created automatically, you have to create it by hand if you want to enable i18n for your project or application.") 27 58 28 59 if domain not in ('django', 'djangojs'): 29 60 raise CommandError("currently makemessages only supports domains 'django' and 'djangojs'") 30 61 … … 35 66 else: 36 67 message = "usage: make-messages.py -l <language>\n or: make-messages.py -a\n" 37 68 raise CommandError(message) 69 70 if not extensions: 71 extensions = ['.html'] 38 72 39 73 languages = [] 40 74 if locale is not None: … … 60 94 all_files.extend([(dirpath, f) for f in filenames]) 61 95 all_files.sort() 62 96 for dirpath, file in all_files: 63 if domain == 'djangojs' and file.endswith('.js'): 97 file_base, file_ext = os.path.splitext(file) 98 if domain == 'djangojs' and file_ext == '.js': 64 99 if verbosity > 1: 65 100 sys.stdout.write('processing file %s in %s\n' % (file, dirpath)) 66 101 src = open(os.path.join(dirpath, file), "rb").read() … … 84 119 if msgs: 85 120 open(potfile, 'ab').write(msgs) 86 121 os.unlink(os.path.join(dirpath, thefile)) 87 elif domain == 'django' and (file .endswith('.py') or file.endswith('.html')):122 elif domain == 'django' and (file_ext == '.py' or file_ext in extensions): 88 123 thefile = file 89 if file .endswith('.html'):124 if file_ext in extensions: 90 125 src = open(os.path.join(dirpath, file), "rb").read() 91 126 thefile = '%s.py' % file 92 127 open(os.path.join(dirpath, thefile), "wb").write(templatize(src)) … … 141 176 help='Verbosity level; 0=minimal output, 1=normal output, 2=all output'), 142 177 make_option('--all', '-a', action='store_true', dest='all', 143 178 default=False, help='Reexamines all source code and templates for new translation strings and updates all message files for all available languages.'), 179 make_option('--extension', '-e', default=None, dest='extensions', 180 help='The file extension(s) to examine (default: ".html", separate multiple extensions with commas, or use -e multiple times)', 181 action='append'), 144 182 ) 145 183 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." 146 184 … … 155 193 domain = options.get('domain') 156 194 verbosity = int(options.get('verbosity')) 157 195 process_all = options.get('all') 196 extensions = options.get('extensions') or [] 158 197 159 make_messages(locale, domain, verbosity, process_all) 198 extensions = handle_extensions(extensions) 199 make_messages(locale, domain, verbosity, process_all, extensions) -
docs/django-admin.txt
diff -r 81d089f1a551 docs/django-admin.txt
a b 411 411 Example usage:: 412 412 413 413 django-admin.py makemessages --all 414 415 --extension 416 ~~~~~~~~~~~ 417 418 Use the ``--extension`` or ``-e`` option to specify a list of file extensions 419 to examine (default: ".html"). 420 421 Example usage:: 422 423 django-admin.py makemessages --locale=de --extension xhtml 424 425 Separate multiple extensions with commas or use -e/--extension multiple times:: 426 427 django-admin.py makemessages --locale=de --extension=tpl,xml --extension=txt 414 428 415 429 --locale 416 430 ~~~~~~~~ -
docs/man/django-admin.1
diff -r 81d089f1a551 docs/man/django-admin.1
a b 49 49 .B sqlall 50 50 for the given app(s) in the current database. 51 51 .TP 52 .BI "makemessages [" "\-\-locale=LOCALE" "] [" "\-\-domain=DOMAIN" "] [" "\-\- all" "]"52 .BI "makemessages [" "\-\-locale=LOCALE" "] [" "\-\-domain=DOMAIN" "] [" "\-\-extension=EXTENSION" "] [" "\-\-all" "]" 53 53 Runs over the entire source tree of the current directory and pulls out all 54 54 strings marked for translation. It creates (or updates) a message file in the 55 55 conf/locale (in the django tree) or locale (for project and application) directory. … … 154 154 .I \-d, \-\-domain=DOMAIN 155 155 The domain of the message files (default: "django") when using makemessages. 156 156 .TP 157 .I \-e, \-\-extension=EXTENSION 158 The file extension(s) to examine (default: ".html", separate multiple 159 extensions with commas, or use -e multiple times). 160 .TP 157 161 .I \-a, \-\-all 158 162 Process all available locales when using makemessages. 159 163 .SH "ENVIRONMENT"