[PATCH 1 of 5] i18n: lookup .mo files in private locale directory

Martin Geisler mg at daimi.au.dk
Fri Jan 9 18:26:41 CST 2009


# HG changeset patch
# User Martin Geisler <mg at daimi.au.dk>
# Date 1231546972 -3600
# Node ID 3520f542f623f467ed5b5d16a01d7c8333333ac6
# Parent  b9bd6f789633db3b91b71dfc6109924fb1d7b24a
i18n: lookup .mo files in private locale directory

This default is to look for /usr/share/locale/xx/LC_MESSAGES/hg.mo for
language xx, but this code will instead do the lookup from locale or
mercurial/locale relative to the root of the Mercurial source tree.

Updated setup.py to ship the xx.po and xx.mo files.

diff -r b9bd6f789633 -r 3520f542f623 mercurial/i18n.py
--- a/mercurial/i18n.py	Fri Jan 09 01:37:54 2009 +0100
+++ b/mercurial/i18n.py	Sat Jan 10 01:22:52 2009 +0100
@@ -7,7 +7,20 @@
 of the GNU General Public License, incorporated herein by reference.
 """
 
-import gettext
-t = gettext.translation('hg', fallback=1)
+import gettext, sys, os
+
+# modelled after templater.templatepath:
+if hasattr(sys, 'frozen'):
+    module = sys.executable
+else:
+    module = __file__
+
+base = os.path.dirname(module)
+for dir in ('.', '..'):
+    localedir = os.path.normpath(os.path.join(base, dir, 'locale'))
+    if os.path.isdir(localedir):
+        break
+
+t = gettext.translation('hg', localedir, fallback=True)
 gettext = t.gettext
 _ = gettext
diff -r b9bd6f789633 -r 3520f542f623 setup.py
--- a/setup.py	Fri Jan 09 01:37:54 2009 +0100
+++ b/setup.py	Sat Jan 10 01:22:52 2009 +0100
@@ -139,6 +139,12 @@
 except ImportError:
     pass
 
+data_files = []
+for root in ('templates', 'po', 'locale'):
+    for dir, dirs, files in os.walk(root):
+        data_files.append((os.path.join('mercurial', dir),
+                           [os.path.join(dir, file_) for file_ in files]))
+
 setup(name='mercurial',
       version=mercurial.version.get_version(),
       author='Matt Mackall',
@@ -149,9 +155,7 @@
       scripts=scripts,
       packages=packages,
       ext_modules=ext_modules,
-      data_files=[(os.path.join('mercurial', root),
-                   [os.path.join(root, file_) for file_ in files])
-                  for root, dirs, files in os.walk('templates')],
+      data_files=data_files,
       cmdclass=cmdclass,
       options=dict(py2exe=dict(packages=['hgext', 'email']),
                    bdist_mpkg=dict(zipdist=True,


More information about the Mercurial-devel mailing list