summaryrefslogtreecommitdiff
path: root/django/bin
diff options
context:
space:
mode:
authorGeorg Bauer <gb@hugo.westfalen.de>2005-12-04 12:06:16 +0000
committerGeorg Bauer <gb@hugo.westfalen.de>2005-12-04 12:06:16 +0000
commit5917fdcf2d07e54e7d83076b26e22bcadf65eb54 (patch)
treeb3232c933fbda8616b40dd96aec1a1f801c635dd /django/bin
parent946bd1e370148efe6ae2da493f000373fa6a35a7 (diff)
added infrastructure code for later javascript translating (currently not active)
git-svn-id: http://code.djangoproject.com/svn/django/trunk@1529 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/bin')
-rwxr-xr-xdjango/bin/make-messages.py55
1 files changed, 41 insertions, 14 deletions
diff --git a/django/bin/make-messages.py b/django/bin/make-messages.py
index 92f6cbfd9a..e8c21db70f 100755
--- a/django/bin/make-messages.py
+++ b/django/bin/make-messages.py
@@ -7,6 +7,8 @@ import getopt
from django.utils.translation import templateize
+pythonize_re = re.compile(r'\n\s*//')
+
localedir = None
if os.path.isdir(os.path.join('conf', 'locale')):
@@ -39,6 +41,9 @@ for o, v in opts:
elif o == '-a':
all = True
+if domain not in ('django', 'djangojs'):
+ print "currently make-messages.py only supports domains 'django' and 'djangojs'"
+ sys.exit(1)
if (lang is None and not all) or domain is None:
print "usage: make-messages.py -l <language>"
print " or: make-messages.py -a"
@@ -66,7 +71,28 @@ for lang in languages:
for (dirpath, dirnames, filenames) in os.walk("."):
for file in filenames:
- if file.endswith('.py') or file.endswith('.html'):
+ if domain == 'djangojs' and file.endswith('.js'):
+ if verbose: sys.stdout.write('processing file %s in %s\n' % (file, dirpath))
+ src = open(os.path.join(dirpath, file), "rb").read()
+ src = pythonize_re.sub('\n#', src)
+ open(os.path.join(dirpath, '%s.py' % file), "wb").write(src)
+ thefile = '%s.py' % file
+ cmd = 'xgettext %s -d %s -L Perl --keyword=gettext_noop --keyword=gettext_lazy --keyword=ngettext_lazy -o - "%s"' % (
+ os.path.exists(potfile) and '--omit-header' or '', domain, os.path.join(dirpath, thefile))
+ (stdin, stdout, stderr) = os.popen3(cmd, 'b')
+ msgs = stdout.read()
+ errors = stderr.read()
+ if errors:
+ print "errors happened while running xgettext on %s" % file
+ print errors
+ sys.exit(8)
+ old = '#: '+os.path.join(dirpath, thefile)[2:]
+ new = '#: '+os.path.join(dirpath, file)[2:]
+ msgs = msgs.replace(old, new)
+ if msgs:
+ open(potfile, 'ab').write(msgs)
+ os.unlink(os.path.join(dirpath, thefile))
+ elif domain == 'django' and (file.endswith('.py') or file.endswith('.html')):
thefile = file
if file.endswith('.html'):
src = open(os.path.join(dirpath, file), "rb").read()
@@ -91,22 +117,23 @@ for lang in languages:
if thefile != file:
os.unlink(os.path.join(dirpath, thefile))
- (stdin, stdout, stderr) = os.popen3('msguniq %s' % potfile, 'b')
- msgs = stdout.read()
- errors = stderr.read()
- if errors:
- print "errors happened while running msguniq"
- print errors
- sys.exit(8)
- open(potfile, 'w').write(msgs)
- if os.path.exists(pofile):
- (stdin, stdout, stderr) = os.popen3('msgmerge -q %s %s' % (pofile, potfile), 'b')
+ if os.path.exists(potfile):
+ (stdin, stdout, stderr) = os.popen3('msguniq %s' % potfile, 'b')
msgs = stdout.read()
errors = stderr.read()
if errors:
- print "errors happened while running msgmerge"
+ print "errors happened while running msguniq"
print errors
sys.exit(8)
- open(pofile, 'wb').write(msgs)
- os.unlink(potfile)
+ open(potfile, 'w').write(msgs)
+ if os.path.exists(pofile):
+ (stdin, stdout, stderr) = os.popen3('msgmerge -q %s %s' % (pofile, potfile), 'b')
+ msgs = stdout.read()
+ errors = stderr.read()
+ if errors:
+ print "errors happened while running msgmerge"
+ print errors
+ sys.exit(8)
+ open(pofile, 'wb').write(msgs)
+ os.unlink(potfile)