mirror of
https://github.com/django/django.git
synced 2025-07-04 09:49:12 +00:00
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
This commit is contained in:
parent
5354de5ddd
commit
2c8a8c3c46
@ -1,5 +1,6 @@
|
|||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
import re
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import getopt
|
import getopt
|
||||||
@ -14,16 +15,19 @@ else:
|
|||||||
print "this script should be run from the django svn tree or your project or app tree"
|
print "this script should be run from the django svn tree or your project or app tree"
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
(opts, args) = getopt.getopt(sys.argv[1:], 'l:d:')
|
(opts, args) = getopt.getopt(sys.argv[1:], 'l:d:v')
|
||||||
|
|
||||||
lang = None
|
lang = None
|
||||||
domain = 'django'
|
domain = 'django'
|
||||||
|
verbose = False
|
||||||
|
|
||||||
for o, v in opts:
|
for o, v in opts:
|
||||||
if o == '-l':
|
if o == '-l':
|
||||||
lang = v
|
lang = v
|
||||||
elif o == '-d':
|
elif o == '-d':
|
||||||
domain = v
|
domain = v
|
||||||
|
elif o == '-v':
|
||||||
|
verbose = True
|
||||||
|
|
||||||
if lang is None or domain is None:
|
if lang is None or domain is None:
|
||||||
print "usage: make-messages.py -l <language>"
|
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)
|
lf = os.path.join(basedir, '%s.po' % domain)
|
||||||
|
|
||||||
|
tpl_re = re.compile(r'{%\s+i18n\s+.*?%}')
|
||||||
|
|
||||||
for (dirpath, dirnames, filenames) in os.walk("."):
|
for (dirpath, dirnames, filenames) in os.walk("."):
|
||||||
for file in filenames:
|
for file in filenames:
|
||||||
if file.endswith('.py') or file.endswith('.html'):
|
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):
|
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:
|
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)
|
os.system(cmd)
|
||||||
|
if thefile != file:
|
||||||
|
os.unlink(os.path.join(dirpath, thefile))
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user