124 """method called by the session handler when the user is authenticated |
124 """method called by the session handler when the user is authenticated |
125 or an anonymous connection is open |
125 or an anonymous connection is open |
126 """ |
126 """ |
127 super(CubicWebRequestBase, self).set_connection(cnx, user) |
127 super(CubicWebRequestBase, self).set_connection(cnx, user) |
128 # set request language |
128 # set request language |
129 vreg = self.vreg |
129 try: |
130 if self.user: |
130 vreg = self.vreg |
131 try: |
131 if self.user: |
132 # 1. user specified language |
132 try: |
133 lang = vreg.typed_value('ui.language', |
133 # 1. user specified language |
134 self.user.properties['ui.language']) |
134 lang = vreg.typed_value('ui.language', |
135 self.set_language(lang) |
135 self.user.properties['ui.language']) |
136 return |
|
137 except KeyError, ex: |
|
138 pass |
|
139 if vreg.config['language-negociation']: |
|
140 # 2. http negociated language |
|
141 for lang in self.header_accept_language(): |
|
142 if lang in self.translations: |
|
143 self.set_language(lang) |
136 self.set_language(lang) |
144 return |
137 return |
145 # 3. default language |
138 except KeyError, ex: |
146 self.set_default_language(vreg) |
139 pass |
147 # XXX code smell |
140 if vreg.config['language-negociation']: |
148 # have to be done here because language is not yet set in setup_params |
141 # 2. http negociated language |
149 # |
142 for lang in self.header_accept_language(): |
150 # special key for created entity, added in controller's reset method |
143 if lang in self.translations: |
151 # if no message set, we don't want this neither |
144 self.set_language(lang) |
152 if '__createdpath' in self.form and self.message: |
145 return |
153 self.message += ' (<a href="%s">%s</a>)' % ( |
146 # 3. default language |
154 self.build_url(self.form.pop('__createdpath')), |
147 self.set_default_language(vreg) |
155 self._('click here to see created entity')) |
148 finally: |
|
149 # XXX code smell |
|
150 # have to be done here because language is not yet set in setup_params |
|
151 # |
|
152 # special key for created entity, added in controller's reset method |
|
153 # if no message set, we don't want this neither |
|
154 if '__createdpath' in self.form and self.message: |
|
155 self.message += ' (<a href="%s">%s</a>)' % ( |
|
156 self.build_url(self.form.pop('__createdpath')), |
|
157 self._('click here to see created entity')) |
156 |
158 |
157 def set_language(self, lang): |
159 def set_language(self, lang): |
158 gettext, self.pgettext = self.translations[lang] |
160 gettext, self.pgettext = self.translations[lang] |
159 self._ = self.__ = gettext |
161 self._ = self.__ = gettext |
160 self.lang = lang |
162 self.lang = lang |