[PATCH 2 of 6] i18n: new build_mo command for setup.py
Martin Geisler
mg at daimi.au.dk
Wed Jan 14 17:16:58 CST 2009
# HG changeset patch
# User Martin Geisler <mg at daimi.au.dk>
# Date 1231974714 -3600
# Node ID 5838464df5cf5fd428bfb43368a535d686642376
# Parent 65bf5325c7a8ed339152759c27e60e1133ebafe1
i18n: new build_mo command for setup.py
This command will generate .mo files under locale/ for the .po files
found under i18n/.
diff -r 65bf5325c7a8 -r 5838464df5cf .hgignore
--- a/.hgignore Thu Jan 15 00:10:54 2009 +0100
+++ b/.hgignore Thu Jan 15 00:11:54 2009 +0100
@@ -28,6 +28,7 @@
tags
cscope.*
i18n/hg.pot
+locale/*/LC_MESSAGES/hg.mo
syntax: regexp
^\.pc/
diff -r 65bf5325c7a8 -r 5838464df5cf setup.py
--- a/setup.py Thu Jan 15 00:10:54 2009 +0100
+++ b/setup.py Thu Jan 15 00:11:54 2009 +0100
@@ -31,6 +31,8 @@
import tempfile
from distutils.core import setup, Extension
from distutils.command.install_data import install_data
+from distutils.command.build import build
+from distutils.spawn import spawn, find_executable
from distutils.ccompiler import new_compiler
import mercurial.version
@@ -104,8 +106,39 @@
('install_lib', 'install_dir'))
install_data.finalize_options(self)
+class build_mo(build):
+
+ description = "build translations (.mo files)"
+
+ def run(self):
+ if not find_executable('msgfmt'):
+ self.warn("could not find msgfmt executable, no translations "
+ "will be built")
+ return
+
+ podir = 'i18n'
+ if not os.path.isdir(podir):
+ self.warn("could not find %s/ directory" % podir)
+ return
+
+ join = os.path.join
+ for po in os.listdir(podir):
+ if not po.endswith('.po'):
+ continue
+ pofile = join(podir, po)
+ modir = join('locale', po[:-3], 'LC_MESSAGES')
+ mofile = join(modir, 'hg.mo')
+ self.mkpath(modir)
+ self.make_file([pofile], mofile, spawn,
+ (['msgfmt', '-o', mofile, pofile],))
+ self.distribution.data_files.append((join('mercurial', modir),
+ [mofile]))
+
+build.sub_commands.append(('build_mo', None))
+
mercurial.version.remember_version(version)
-cmdclass = {'install_data': install_package_data}
+cmdclass = {'install_data': install_package_data,
+ 'build_mo': build_mo}
ext_modules=[
Extension('mercurial.base85', ['mercurial/base85.c']),
More information about the Mercurial-devel
mailing list