# HG changeset patch # User Goffi # Date 1554923194 -7200 # Node ID 6424d3684d1e12f022c79e02e60556a16bf12680 # Parent ef3adc3f2078533e2b918f228ec34727f510169d 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. diff -r ef3adc3f2078 -r 6424d3684d1e libervia/server/pages.py --- 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) diff -r ef3adc3f2078 -r 6424d3684d1e libervia/server/session_iface.py --- a/libervia/server/session_iface.py Sun Mar 03 17:14:27 2019 +0100 +++ b/libervia/server/session_iface.py Wed Apr 10 21:06:34 2019 +0200 @@ -47,6 +47,7 @@ self.uuid = unicode(shortuuid.uuid()) self.identities = data_objects.Identities() self.csrf_token = unicode(shortuuid.uuid()) + self.locale = None # i18n of the pages self.pages_data = {} # used to keep data accross reloads (key is page instance) self.affiliations = OrderedDict() # cache for node affiliations