[web-request] handle default language earlier
authorPierre-Yves David <pierre-yves.david@logilab.fr>
Wed, 19 Jun 2013 12:00:54 +0200
changeset 9037 6fd0ac6506cb
parent 9036 cf519fd876c6
child 9038 1b972d81eda4
[web-request] handle default language earlier We now read language negotiation header at initialisation time (previously done during ``set_session``). This simplify the set_session code for later reworking. There is no change in behavior, the user selected language continue to overwrite the one picked from the header/default when applicable. related to #2503918
web/request.py
--- a/web/request.py	Tue Jun 18 15:12:25 2013 +0200
+++ b/web/request.py	Wed Jun 19 12:00:54 2013 +0200
@@ -119,6 +119,19 @@
         self.setup_params(form)
         #: received body
         self.content = StringIO()
+        # use header to set default language (may ne overwriten by user one later)
+        if vreg.config.get('language-negociation', False):
+            # http negociated language
+            accepted_languages = self.header_accept_language()
+        else:
+            accepted_languages = ()
+        for lang in accepted_languages:
+            if lang in self.translations:
+                self.set_language(lang)
+                break
+        else:
+            self.set_default_language(vreg)
+        # 3. default language
         #: dictionary that may be used to store request data that has to be
         #: shared among various components used to publish the request (views,
         #: controller, application...)
@@ -222,14 +235,6 @@
                 return
             except KeyError:
                 pass
-        if vreg.config['language-negociation']:
-            # 2. http negociated language
-            for lang in self.header_accept_language():
-                if lang in self.translations:
-                    self.set_language(lang)
-                    return
-        # 3. default language
-        self.set_default_language(vreg)
 
     # input form parameters management ########################################