Author: ianb
Date: 2008-09-30 11:34:29 -0600 (Tue, 30 Sep 2008)
New Revision: 3608
Modified:
FormEncode/trunk/docs/news.txt
FormEncode/trunk/formencode/api.py
Log:
Look in /usr/share/locale for locale files, in addition to the normal
locations. From Toshio Kuratomi
Modified: FormEncode/trunk/docs/news.txt
===================================================================
--- FormEncode/trunk/docs/news.txt 2008-09-29 21:01:24 UTC (rev 3607)
+++ FormEncode/trunk/docs/news.txt 2008-09-30 17:34:29 UTC (rev 3608)
@@ -41,6 +41,9 @@
* Added :class:`formencode.validators.XRI` for validation i-names,
i-numbers, URLs, etc (as used in OpenID).
+* Look in ``/usr/share/locale`` for locale files, in addition to the
+ normal locations.
+
1.0.1
-----
Modified: FormEncode/trunk/formencode/api.py
===================================================================
--- FormEncode/trunk/formencode/api.py 2008-09-29 21:01:24 UTC (rev 3607)
+++ FormEncode/trunk/formencode/api.py 2008-09-30 17:34:29 UTC (rev 3608)
@@ -17,17 +17,36 @@
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)
-------------------------------------------------------------------------
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-CVS mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/formencode-cvs