[Mpuls-commits] r1533 - wasko/branches/2.0/mpulsweb/lib
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Fri Feb 12 14:59:48 CET 2010
Author: torsten
Date: 2010-02-12 14:59:44 +0100 (Fri, 12 Feb 2010)
New Revision: 1533
Modified:
wasko/branches/2.0/mpulsweb/lib/base.py
Log:
* mpulsweb/lib/base.py (BaseController.__before__): Set translation
language based on browser settings. Fall back to default language
(locale) if not possible.
Modified: wasko/branches/2.0/mpulsweb/lib/base.py
===================================================================
--- wasko/branches/2.0/mpulsweb/lib/base.py 2010-02-12 13:08:57 UTC (rev 1532)
+++ wasko/branches/2.0/mpulsweb/lib/base.py 2010-02-12 13:59:44 UTC (rev 1533)
@@ -30,6 +30,7 @@
import md5
import logging
+import locale
from time import time
from paste.httpexceptions import HTTPUnauthorized, HTTPNotFound
@@ -38,6 +39,7 @@
from pylons.controllers import WSGIController
from pylons.controllers.util import redirect_to
from pylons.i18n import _
+from pylons.i18n.translation import set_lang
from pylons.templating import render
import mpulsweb.lib.db as db
@@ -46,8 +48,6 @@
import mpulsweb.lib.helpers as h
from mpulsweb.lib.security import getDbName, userIdentity
-
-
# These names are exported from this module largely for historical
# reasons. Ideally the module should probably only export
# BaseController and render which are customarily imported from this
@@ -86,6 +86,25 @@
except KeyError:
pass
+ # Set language for translation based an browser setting. Default locales.
+ # TODO: pylons.i18n.translation (_get_translator) still tries to load
+ # language files for "waskaweb". It seems to be defined in
+ # conf['pylons.package']. I do not know how this var gets set during
+ # application init.
+ deflang = locale.getlocale()[0]
+ for lang in request.languages:
+
+ try:
+ log.debug('Trying to set lang to %s' % lang)
+ set_lang(lang)
+ log.debug('Ok. Lang set to %s' % lang)
+ break;
+ except Exception, e:
+ log.exception(e)
+ log.debug('Trying to set lang to default: %s' % deflang)
+ set_lang(deflang)
+ log.debug('Ok. Lang set to %s' % deflang)
+
# Check if the user is already authorized.
# If not then redirect the user to the login page
try:
More information about the Mpuls-commits
mailing list