Mercurial > libervia-web
diff libervia/server/pages.py @ 1165:6424d3684d1e
pages: locale handling:
language/locale can be set using C.KEY_LANG in url query (e.g. [url]?lang=fr), it is set for the whole session.
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 10 Apr 2019 21:06:34 +0200 |
parents | 64952ba7affe |
children | 7d2e098ea3f4 |
line wrap: on
line diff
--- a/libervia/server/pages.py Sun Mar 03 17:14:27 2019 +0100 +++ b/libervia/server/pages.py Wed Apr 10 21:06:34 2019 +0200 @@ -1137,13 +1137,17 @@ request.finish() else: template = u"error/" + unicode(code) + ".html" + template_data = request.template_data + session_data = self.host.getSessionData(request, session_iface.ISATSession) + if session_data.locale is not None: + template_data[u'locale'] = session_data.locale if self.vhost_root.site_name: - request.template_data[u'site'] = self.vhost_root.site_name + template_data[u'site'] = self.vhost_root.site_name rendered = self.host.renderer.render( template, error_code=code, - **request.template_data + **template_data ) self.writeData(rendered, request) @@ -1214,6 +1218,8 @@ session_data = self.host.getSessionData(request, session_iface.ISATSession) if session_data.popPageFlag(self, C.FLAG_CONFIRM): template_data[u"confirm"] = True + if session_data.locale is not None: + template_data[u'locale'] = session_data.locale if self.vhost_root.site_name: template_data[u'site'] = self.vhost_root.site_name @@ -1413,6 +1419,8 @@ _(u"renderPartial must only be used with dynamic pages") ) session_data = self.host.getSessionData(request, session_iface.ISATSession) + if session_data.locale is not None: + template_data[u'locale'] = session_data.locale if self.vhost_root.site_name: template_data[u'site'] = self.vhost_root.site_name @@ -1465,6 +1473,13 @@ # we don't differenciate URLs finishing with '/' or not del request.postpath[-1] + if C.KEY_LANG in request.args: + try: + session_data.locale = request.args.pop(C.KEY_LANG)[0] + except IndexError: + log.warning(u"empty lang received") + + d = defer.Deferred() d.addCallback(self._checkAccess, request)