1
0
mirror of https://github.com/django/django.git synced 2025-07-04 17:59:13 +00:00

i18n: added -a switch to make-messags.py to run xgettext on all messagefiles

git-svn-id: http://code.djangoproject.com/svn/django/branches/i18n@907 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Georg Bauer 2005-10-17 14:37:26 +00:00
parent 3c68633d57
commit f3723ce84b

View File

@ -5,21 +5,22 @@ import os
import sys import sys
import getopt import getopt
basedir = None localedir = None
if os.path.isdir(os.path.join('conf', 'locale')): if os.path.isdir(os.path.join('conf', 'locale')):
basedir = os.path.abspath(os.path.join('conf', 'locale')) localedir = os.path.abspath(os.path.join('conf', 'locale'))
elif os.path.isdir('locale'): elif os.path.isdir('locale'):
basedir = os.path.abspath('locale') localedir = os.path.abspath('locale')
else: 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:v') (opts, args) = getopt.getopt(sys.argv[1:], 'l:d:va')
lang = None lang = None
domain = 'django' domain = 'django'
verbose = False verbose = False
all = False
for o, v in opts: for o, v in opts:
if o == '-l': if o == '-l':
@ -28,14 +29,20 @@ for o, v in opts:
domain = v domain = v
elif o == '-v': elif o == '-v':
verbose = True verbose = True
elif o == '-a':
all = True
if lang is None or domain is None: if (lang is None and not all) or domain is None:
print "usage: make-messages.py -l <language>" print "usage: make-messages.py -l <language>"
print " or: make-messages.py -a"
sys.exit(1) sys.exit(1)
basedir = os.path.join(basedir, lang, 'LC_MESSAGES') languages = []
if not os.path.isdir(basedir):
os.makedirs(basedir) if lang is not None:
languages.append(lang)
elif all:
languages = [el for el in os.listdir(localedir) if not el.startswith('.')]
dot_re = re.compile('\S') dot_re = re.compile('\S')
def blank(src): def blank(src):
@ -60,37 +67,44 @@ def templateize(src):
going = 0 going = 0
return ''.join(o) return ''.join(o)
pofile = os.path.join(basedir, '%s.po' % domain) for lang in languages:
potfile = os.path.join(basedir, '%s.pot' % domain)
if os.path.exists(potfile): print "processing language", lang
basedir = os.path.join(localedir, lang, 'LC_MESSAGES')
if not os.path.isdir(basedir):
os.makedirs(basedir)
pofile = os.path.join(basedir, '%s.po' % domain)
potfile = os.path.join(basedir, '%s.pot' % domain)
if os.path.exists(potfile):
os.unlink(potfile)
for (dirpath, dirnames, filenames) in os.walk("."):
for file in filenames:
if file.endswith('.py') or file.endswith('.html'):
thefile = file
if file.endswith('.html'):
src = open(os.path.join(dirpath, file), "rb").read()
open(os.path.join(dirpath, '%s.py' % file), "wb").write(templateize(src))
thefile = '%s.py' % file
if verbose: sys.stdout.write('processing file %s in %s\n' % (file, dirpath))
cmd = 'xgettext %s -d %s -L Python --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))
msgs = os.popen(cmd, 'r').read()
if thefile != file:
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)
if thefile != file:
os.unlink(os.path.join(dirpath, thefile))
msgs = os.popen('msguniq %s' % potfile, 'r').read()
open(potfile, 'w').write(msgs)
if os.path.exists(pofile):
msgs = os.popen('msgmerge %s %s' % (pofile, potfile), 'r').read()
open(pofile, 'wb').write(msgs)
os.unlink(potfile) os.unlink(potfile)
for (dirpath, dirnames, filenames) in os.walk("."):
for file in filenames:
if file.endswith('.py') or file.endswith('.html'):
thefile = file
if file.endswith('.html'):
src = open(os.path.join(dirpath, file), "rb").read()
open(os.path.join(dirpath, '%s.py' % file), "wb").write(templateize(src))
thefile = '%s.py' % file
if verbose: sys.stdout.write('processing file %s in %s\n' % (file, dirpath))
cmd = 'xgettext %s -d %s -L Python --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))
msgs = os.popen(cmd, 'r').read()
if thefile != file:
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)
if thefile != file:
os.unlink(os.path.join(dirpath, thefile))
msgs = os.popen('msguniq %s' % potfile, 'r').read()
open(potfile, 'w').write(msgs)
if os.path.exists(pofile):
msgs = os.popen('msgmerge %s %s' % (pofile, potfile), 'r').read()
open(pofile, 'wb').write(msgs)
os.unlink(potfile)