summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorg Bauer <gb@hugo.westfalen.de>2005-09-29 21:07:35 +0000
committerGeorg Bauer <gb@hugo.westfalen.de>2005-09-29 21:07:35 +0000
commit2c8a8c3c467bbc3bffb81c9fbd9a8d629901905e (patch)
treedefde931e7f3ae5b3327f7a6a2044865b40c356a
parent5354de5ddd0d1f936fbb6c59abb08f64d396a47c (diff)
made make-messages.py more intelligent with template scanning
git-svn-id: http://code.djangoproject.com/svn/django/branches/i18n@729 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rwxr-xr-xdjango/bin/make-messages.py24
1 files changed, 20 insertions, 4 deletions
diff --git a/django/bin/make-messages.py b/django/bin/make-messages.py
index 16de1ff366..d445335915 100755
--- a/django/bin/make-messages.py
+++ b/django/bin/make-messages.py
@@ -1,5 +1,6 @@
#!/usr/bin/python
+import re
import os
import sys
import getopt
@@ -14,16 +15,19 @@ else:
print "this script should be run from the django svn tree or your project or app tree"
sys.exit(1)
-(opts, args) = getopt.getopt(sys.argv[1:], 'l:d:')
+(opts, args) = getopt.getopt(sys.argv[1:], 'l:d:v')
lang = None
domain = 'django'
+verbose = False
for o, v in opts:
if o == '-l':
lang = v
elif o == '-d':
domain = v
+ elif o == '-v':
+ verbose = True
if lang is None or domain is None:
print "usage: make-messages.py -l <language>"
@@ -35,13 +39,25 @@ if not os.path.isdir(basedir):
lf = os.path.join(basedir, '%s.po' % domain)
+tpl_re = re.compile(r'{%\s+i18n\s+.*?%}')
+
for (dirpath, dirnames, filenames) in os.walk("."):
for file in filenames:
if file.endswith('.py') or file.endswith('.html'):
- sys.stderr.write('processing file %s in %s\n' % (file, dirpath))
+ thefile = file
+ if file.endswith('.html'):
+ src = open(os.path.join(dirpath, file), "rb").read()
+ lst = []
+ for match in tpl_re.findall(src):
+ lst.append(match)
+ open(os.path.join(dirpath, '%s.py' % file), "wb").write('\n'.join(lst))
+ thefile = '%s.py' % file
+ if verbose: sys.stdout.write('processing file %s in %s\n' % (file, dirpath))
if os.path.isfile(lf):
- cmd = 'xgettext -j -d %s -L Python -p %s %s' % (domain, basedir, os.path.join(dirpath, file))
+ cmd = 'xgettext -j -d %s -L Python -p %s %s' % (domain, basedir, os.path.join(dirpath, thefile))
else:
- cmd = 'xgettext -d %s -L Python -p %s %s' % (domain, basedir, os.path.join(dirpath, file))
+ cmd = 'xgettext -d %s -L Python -p %s %s' % (domain, basedir, os.path.join(dirpath, thefile))
os.system(cmd)
+ if thefile != file:
+ os.unlink(os.path.join(dirpath, thefile))