1
1
#!/usr/bin/env python
7
def compile_messages(locale=None):
10
if os.path.isdir(os.path.join('conf', 'locale')):
11
basedir = os.path.abspath(os.path.join('conf', 'locale'))
12
elif os.path.isdir('locale'):
13
basedir = os.path.abspath('locale')
15
print "This script should be run from the Django SVN tree or your project or app tree."
18
if locale is not None:
19
basedir = os.path.join(basedir, locale, 'LC_MESSAGES')
21
for dirpath, dirnames, filenames in os.walk(basedir):
24
sys.stderr.write('processing file %s in %s\n' % (f, dirpath))
25
pf = os.path.splitext(os.path.join(dirpath, f))[0]
26
# Store the names of the .mo and .po files in an environment
27
# variable, rather than doing a string replacement into the
28
# command, so that we can take advantage of shell quoting, to
29
# quote any malicious characters/escaping.
30
# See http://cyberelk.net/tim/articles/cmdline/ar01s02.html
31
os.environ['djangocompilemo'] = pf + '.mo'
32
os.environ['djangocompilepo'] = pf + '.po'
33
if sys.platform == 'win32': # Different shell-variable syntax
34
cmd = 'msgfmt -o "%djangocompilemo%" "%djangocompilepo%"'
36
cmd = 'msgfmt -o "$djangocompilemo" "$djangocompilepo"'
40
parser = optparse.OptionParser()
41
parser.add_option('-l', '--locale', dest='locale',
42
help="The locale to process. Default is to process all.")
43
options, args = parser.parse_args()
45
parser.error("This program takes no arguments")
46
compile_messages(options.locale)
48
3
if __name__ == "__main__":
6
args = ' '.join(sys.argv[1:])
7
print >> sys.stderr, "%s has been moved into django-admin.py" % name
8
print >> sys.stderr, 'Please run "django-admin.py compilemessages %s" instead.'% args