Ticket #5463: make-messages.1.diff
File make-messages.1.diff, 7.2 KB (added by , 16 years ago) |
---|
-
django/bin/make-messages.py
2 2 3 3 import os 4 4 import optparse 5 from django.core.management.commands.makemessages import make_messages 5 from django.core.management.commands.makemessages import make_messages, handle_extensions 6 6 7 7 def main(): 8 8 parser = optparse.OptionParser() … … 17 17 default=False, help='Reexamines all source code and templates for \ 18 18 new translation strings and updates all message files for all \ 19 19 available languages.') 20 parser.add_option('-e', '--extension', default=[], dest='extensions', 21 help='The file extension(s) to examine (default: ".html", separate multiple extensions with commas, or use -e multiple times)', 22 action='append'), 20 23 21 24 options, args = parser.parse_args() 22 25 if len(args): … … 25 28 verbosity = 2 26 29 else: 27 30 verbosity = 1 28 31 32 extensions = handle_extensions(options.extensions) 33 print extensions 29 34 make_messages(locale=options.locale, domain=options.domain, 30 verbosity=verbosity, all=options.all )35 verbosity=verbosity, all=options.all, extensions=extensions) 31 36 32 37 if __name__ == "__main__": 33 38 main() -
docs/django-admin.txt
390 390 391 391 django-admin.py makemessages --all 392 392 393 --extension 394 ~~~~~~~~~~~ 395 396 Use the ``--extension`` or ``-e`` option to specify a list of file extensions 397 to examine (default: ".html"). 398 399 Example usage:: 400 401 django-admin.py makemessages --locale=de --extension xhtml 402 403 Separate multiple extensions with commas or use -e/--extension multiple times:: 404 405 django-admin.py makemessages --locale=de --extension=tpl,xml --extension=txt 406 393 407 --locale 394 408 ~~~~~~~~ 395 409 -
docs/man/django-admin.1
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" -
django/core/management/commands/makemessages.py
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 >>> organize_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=['.html']): 11 42 """ 12 43 Uses the locale directory from the Django SVN tree or an application/ 13 44 project to process all … … 61 92 all_files.extend([(dirpath, f) for f in filenames]) 62 93 all_files.sort() 63 94 for dirpath, file in all_files: 64 if domain == 'djangojs' and file.endswith('.js'): 95 file_base, file_ext = os.path.splitext(file) 96 if domain == 'djangojs' and file_ext == '.js': 65 97 if verbosity > 1: 66 98 sys.stdout.write('processing file %s in %s\n' % (file, dirpath)) 67 99 src = open(os.path.join(dirpath, file), "rb").read() … … 87 119 if msgs: 88 120 open(potfile, 'ab').write(msgs) 89 121 os.unlink(os.path.join(dirpath, thefile)) 90 elif domain == 'django' and (file .endswith('.py') or file.endswith('.html')):122 elif domain == 'django' and (file_ext == '.py' or file_ext in extensions): 91 123 thefile = file 92 if file .endswith('.html'):124 if file_ext in extensions: 93 125 src = open(os.path.join(dirpath, file), "rb").read() 94 126 thefile = '%s.py' % file 95 127 open(os.path.join(dirpath, thefile), "wb").write(templatize(src)) … … 150 182 help='Verbosity level; 0=minimal output, 1=normal output, 2=all output'), 151 183 make_option('--all', '-a', action='store_true', dest='all', 152 184 default=False, help='Reexamines all source code and templates for new translation strings and updates all message files for all available languages.'), 185 make_option('--extension', '-e', default=[], dest='extensions', 186 help='The file extension(s) to examine (default: ".html", separate multiple extensions with commas, or use -e multiple times)', 187 action='append'), 153 188 ) 154 189 help = "Runs over the entire source tree of the current directory and pulls out all strings marked for translation. It creates (or updates) a message file in the conf/locale (in the django tree) or locale (for project and application) directory." 155 190 … … 164 199 domain = options.get('domain') 165 200 verbosity = int(options.get('verbosity')) 166 201 process_all = options.get('all') 167 168 make_messages(locale, domain, verbosity, process_all) 202 extensions = options.get('extensions') 203 204 extensions = organize_extensions(extensions) 205 make_messages(locale, domain, verbosity, process_all, extensions)