Patch for locale placement
Toshio Kuratomi <[email protected]> Mon, 29 Sep 2008 13:30:29 -0700
| Newsgroups | gmane.comp.python.formencode |
|---|---|
| Message-ID | <[email protected]> |
Hello all, I'm working on the formencode package for Fedora and noticed the i18n directory with the locales wasn't being placed in the system catalog. There's two parts to making that work: 1) Be able to find the locales whether they live in the egg or in the system catalog. 2) Have the package install the files in the right place depending on whether an egg is being built or the files are being placed on the system in expanded form. setuptools makes #2 hard to accomplish so I haven't even attempted it for this pass. I've struggled with setuptools where I am upstream and don't have any solution that seems clean to me yet. If I get something working in the future, I'll send another patch to do so. I have made a patch for #1 that should work, though. With the attached patch, I can move the i18n files to the system catalog manually in the package's build script after the package is installed and formencode will properly find them. It first uses pkg_resources to try to find the files in the place that setuptools will install them. Does this seem acceptable to you? PS: I noticed there's a locale directory: formencode/i18n/big5. The problem is big5 isn't a locale. It's an encoding like utf-8 or latin-1. There are locales that have that as an encoding. They'd look like zh_TW.big5, or zh_HK.big5. Looking at the .po file in the big5 directory, though, it seems like the encoding is utf-8, not big-5. Probably the author of the translation wants to express that the translation is something other than zh_CN (Simplified Chinese). It should be renamed appropriately once the author specifies what language it's for. -Toshio ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ FormEncode-discuss mailing list FormEncode-discuss-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org https://lists.sourceforge.net/lists/listinfo/formencode-discuss
formencode-translations-system.patch
(text/x-patch, 1.6 KB)
Index: FormEncode-1.0.1/formencode/api.py
===================================================================
--- FormEncode-1.0.1.orig/formencode/api.py
+++ FormEncode-1.0.1/formencode/api.py
@@ -17,17 +17,36 @@ __all__ = ['NoDefault', 'Invalid', 'Vali
import gettext
def get_localedir():
+ """
+ Retrieve the location of locales.
+
+ If we're built as an egg, we need to find the resource within the egg.
+ Otherwise, we need to look for the locales on the filesystem or in the
+ system message catalog.
+ """
+ locale_dir = ''
+ # Check the egg first
if resource_filename is not None:
try:
- return resource_filename(__name__, "/i18n")
+ locale_dir = resource_filename(__name__, "/i18n")
except NotImplementedError:
# resource_filename doesn't work with non-egg zip files
pass
- return os.path.join(os.path.dirname(__file__), 'i18n')
+ if os.access(locale_dir, os.R_OK | os.X_OK):
+ # If the resource is present in the egg, use it
+ return locale_dir
+
+ # Otherwise, search the filesystem
+ locale_dir = os.path.join(os.path.dirname(__file__), 'i18n')
+ if not os.access(locale_dir, os.R_OK | os.X_OK):
+ # Fallback on the system catalog
+ locale_dir = os.path.normpath('/usr/share/locale')
+
+ return locale_dir
def set_stdtranslation(domain="FormEncode", languages=None, \
localedir = get_localedir()):
-
+
t = gettext.translation(domain=domain, \
languages=languages, \
localedir=localedir, fallback=True)
signature.asc
(application/pgp-signature, 197 B)
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iEYEARECAAYFAkjhOuYACgkQX6yAic2E7khLBACdFs8FwhYokMB95BrhkZVre17R QiMAnRmbOLZ5SPIi8Xq2aZxjimWW2d2b =zJig -----END PGP SIGNATURE-----