Mercurial > libervia-web
changeset 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 (2019-04-10) |
parents | ef3adc3f2078 |
children | 5baf7ece44a0 |
files | libervia/server/pages.py libervia/server/session_iface.py |
diffstat | 2 files changed, 18 insertions(+), 2 deletions(-) [+] |
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)
--- 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