changeset 5373:7c9372ef5428

fix browser language detection
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 13 Dec 2009 13:57:21 +0100
parents 4a406029ad23
children 52c4c1bf901d
files MoinMoin/wsgiapp.py
diffstat 1 files changed, 23 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/wsgiapp.py	Fri Dec 11 22:57:15 2009 +0100
+++ b/MoinMoin/wsgiapp.py	Sun Dec 13 13:57:21 2009 +0100
@@ -214,26 +214,38 @@
     if i18n.languages is None:
         i18n.i18n_init(context)
 
-    cfg = context.cfg
     lang = None
-    if i18n.languages and not cfg.language_ignore_browser:
-        for l in context.request.accept_languages:
-            if l in i18n.languages:
-                lang = l
-                break
-    if lang is None and cfg.language_default in i18n.languages:
-        lang = cfg.language_default
-    else:
+    if i18n.languages:
+        cfg = context.cfg
+        if not cfg.language_ignore_browser:
+            for l, w in context.request.accept_languages:
+                logging.debug("client accepts language %r, weight %r" % (l, w))
+                if l in i18n.languages:
+                    logging.debug("moin supports language %r" % l)
+                    lang = l
+                    break
+            else:
+                logging.debug("moin does not support any language client accepts")
+                if cfg.language_default in i18n.languages:
+                    lang = cfg.language_default
+                    logging.debug("fall back to cfg.language_default (%r)" % lang)
+    if not lang:
         lang = 'en'
+        logging.debug("emergency fallback to 'en'")
+    logging.debug("setup_i18n_preauth returns %r" % lang)
     return lang
 
 def setup_i18n_postauth(context):
     """ Determine language for the request after user-id is established. """
     user = context.user
     if user and user.valid and user.language:
-        return user.language
+        logging.debug("valid user that has configured some specific language to use in his user profile")
+        lang = user.language
     else:
-        return context.lang
+        logging.debug("either no valid user or no specific language configured in user profile, using lang setup by setup_i18n_preauth")
+        lang = context.lang
+    logging.debug("setup_i18n_postauth returns %r" % lang)
+    return lang
 
 class Application(object):
     def __init__(self, app_config=None):