Ticket #5463: 5463.diff
File 5463.diff, 2.6 KB (added by , 17 years ago) |
---|
-
trunk/django/bin/make-messages.py
11 11 import getopt 12 12 from itertools import dropwhile 13 13 14 TEMPLATE_EXTENSIONS = ('.html', '.tpl', '.xml', '.txt') 15 14 16 pythonize_re = re.compile(r'\n\s*//') 15 17 16 18 def make_messages(): 19 global TEMPLATE_EXTENSIONS 17 20 localedir = None 18 21 19 22 if os.path.isdir(os.path.join('conf', 'locale')): … … 29 32 print "you want to enable i18n for your project or application." 30 33 sys.exit(1) 31 34 32 (opts, args) = getopt.getopt(sys.argv[1:], 'l:d:va ')35 (opts, args) = getopt.getopt(sys.argv[1:], 'l:d:vae') 33 36 34 37 lang = None 35 38 domain = 'django' … … 45 48 verbose = True 46 49 elif o == '-a': 47 50 all = True 48 51 elif o == '-e': 52 TEMPLATE_EXTENSIONS = args 53 49 54 if domain not in ('django', 'djangojs'): 50 55 print "currently make-messages.py only supports domains 'django' and 'djangojs'" 51 56 sys.exit(1) … … 62 67 languages = [el for el in os.listdir(localedir) if not el.startswith('.')] 63 68 64 69 for lang in languages: 65 66 70 print "processing language", lang 67 71 basedir = os.path.join(localedir, lang, 'LC_MESSAGES') 68 72 if not os.path.isdir(basedir): … … 76 80 77 81 for (dirpath, dirnames, filenames) in os.walk("."): 78 82 for file in filenames: 79 if domain == 'djangojs' and file.endswith('.js'): 83 file_base, file_ext = os.path.splitext(file) 84 if domain == 'djangojs' and file_ext == 'js': 80 85 if verbose: sys.stdout.write('processing file %s in %s\n' % (file, dirpath)) 81 86 src = open(os.path.join(dirpath, file), "rb").read() 82 87 src = pythonize_re.sub('\n#', src) … … 97 102 if msgs: 98 103 open(potfile, 'ab').write(msgs) 99 104 os.unlink(os.path.join(dirpath, thefile)) 100 elif domain == 'django' and (file .endswith('.py') or file.endswith('.html')):105 elif domain == 'django' and (file_ext == 'py' or file_ext in TEMPLATE_EXTENSIONS): 101 106 thefile = file 102 if file .endswith('.html'):107 if file_ext in TEMPLATE_EXTENSIONS: 103 108 src = open(os.path.join(dirpath, file), "rb").read() 104 109 thefile = '%s.py' % file 105 110 open(os.path.join(dirpath, thefile), "wb").write(templatize(src))