[PATCH 5 of 6] lookup .mo files in private locale directory

Martin Geisler mg at daimi.au.dk
Fri Sep 5 18:11:21 CDT 2008


# HG changeset patch
# User Martin Geisler <mg at daimi.au.dk>
# Date 1220655371 -7200
# Node ID 9d15008f375612a6bc3dfaf509cb68bdb704856a
# Parent  282cefd6b6cd3e37a367aeecb1467fc95dc6537a
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 --git a/mercurial/i18n.py b/mercurial/i18n.py
--- a/mercurial/i18n.py
+++ b/mercurial/i18n.py
@@ -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 --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -116,6 +116,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',
@@ -126,9 +132,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