Changeset 729
- Timestamp:
- 09/29/05 16:07:35 (3 years ago)
- Files:
-
- django/branches/i18n/django/bin/make-messages.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/i18n/django/bin/make-messages.py
r727 r729 1 1 #!/usr/bin/python 2 2 3 import re 3 4 import os 4 5 import sys … … 15 16 sys.exit(1) 16 17 17 (opts, args) = getopt.getopt(sys.argv[1:], 'l:d: ')18 (opts, args) = getopt.getopt(sys.argv[1:], 'l:d:v') 18 19 19 20 lang = None 20 21 domain = 'django' 22 verbose = False 21 23 22 24 for o, v in opts: … … 25 27 elif o == '-d': 26 28 domain = v 29 elif o == '-v': 30 verbose = True 27 31 28 32 if lang is None or domain is None: … … 36 40 lf = os.path.join(basedir, '%s.po' % domain) 37 41 42 tpl_re = re.compile(r'{%\s+i18n\s+.*?%}') 43 38 44 for (dirpath, dirnames, filenames) in os.walk("."): 39 45 for file in filenames: 40 46 if file.endswith('.py') or file.endswith('.html'): 41 sys.stderr.write('processing file %s in %s\n' % (file, dirpath)) 47 thefile = file 48 if file.endswith('.html'): 49 src = open(os.path.join(dirpath, file), "rb").read() 50 lst = [] 51 for match in tpl_re.findall(src): 52 lst.append(match) 53 open(os.path.join(dirpath, '%s.py' % file), "wb").write('\n'.join(lst)) 54 thefile = '%s.py' % file 55 if verbose: sys.stdout.write('processing file %s in %s\n' % (file, dirpath)) 42 56 if os.path.isfile(lf): 43 cmd = 'xgettext -j -d %s -L Python -p %s %s' % (domain, basedir, os.path.join(dirpath, file))57 cmd = 'xgettext -j -d %s -L Python -p %s %s' % (domain, basedir, os.path.join(dirpath, thefile)) 44 58 else: 45 cmd = 'xgettext -d %s -L Python -p %s %s' % (domain, basedir, os.path.join(dirpath, file))59 cmd = 'xgettext -d %s -L Python -p %s %s' % (domain, basedir, os.path.join(dirpath, thefile)) 46 60 os.system(cmd) 61 if thefile != file: 62 os.unlink(os.path.join(dirpath, thefile)) 47 63
