[PATCH 3 of 4] lookup .mo files in private locale directory

Martin Geisler mg at daimi.au.dk
Fri Aug 22 15:51:16 CDT 2008


# HG changeset patch
# User Martin Geisler <mg at daimi.au.dk>
# Date 1219437246 -7200
# Node ID a620e5e08782460b488ff15d11a614482050e262
# Parent  6f5c49b0488dca5f5cb3ddfe14f6bbdb34bce5a5
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 6f5c49b0488d -r a620e5e08782 mercurial/i18n.py
--- a/mercurial/i18n.py	Fri Aug 22 22:34:01 2008 +0200
+++ b/mercurial/i18n.py	Fri Aug 22 22:34:06 2008 +0200
@@ -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 6f5c49b0488d -r a620e5e08782 setup.py
--- a/setup.py	Fri Aug 22 22:34:01 2008 +0200
+++ b/setup.py	Fri Aug 22 22:34:06 2008 +0200
@@ -115,6 +115,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',
@@ -125,9 +131,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