No translation in pviews
Problem
In a pview, from cubicweb import _
and self._cw._
do not translate, so it just returns the string that was given as argument. It is also the case of self._cw.user._cw._
.
Remarks
- However
self._cw.user.prefered_language()
returns a good result. - It is at least the case with version 3.26.18 of CubicWeb.
Technical notes
From where is it given?
Stack trace of a pview
File /home/nspanti/.virtualenvs/nemo/local/lib/python2.7/site-packages/pyramid/tweens.py, line 41, function excview_tween:
response = handler(request)
File /home/nspanti/.virtualenvs/nemo/local/lib/python2.7/site-packages/cubicweb/pyramid/bwcompat.py, line 192, function __call__:
response = self.handler(request)
File /home/nspanti/.virtualenvs/nemo/local/lib/python2.7/site-packages/pyramid/router.py, line 148, function handle_request:
registry, request, context, context_iface, view_name
File /home/nspanti/.virtualenvs/nemo/local/lib/python2.7/site-packages/pyramid/view.py, line 667, function _call_view:
response = view_callable(context, request)
File /home/nspanti/.virtualenvs/nemo/local/lib/python2.7/site-packages/pyramid/config/views.py, line 169, function __call__:
return view(context, request)
File /home/nspanti/.virtualenvs/nemo/local/lib/python2.7/site-packages/pyramid/config/views.py, line 188, function attr_view:
return view(context, request)
File /home/nspanti/.virtualenvs/nemo/local/lib/python2.7/site-packages/pyramid/config/views.py, line 214, function predicate_wrapper:
return view(context, request)
File /home/nspanti/.virtualenvs/nemo/local/lib/python2.7/site-packages/pyramid/viewderivers.py, line 384, function authdebug_view:
return view(context, request)
File /home/nspanti/.virtualenvs/nemo/local/lib/python2.7/site-packages/pyramid/viewderivers.py, line 436, function rendered_view:
result = view(context, request)
File /home/nspanti/.virtualenvs/nemo/local/lib/python2.7/site-packages/pyramid/viewderivers.py, line 144, function _requestonly_view:
response = view(request)
Research in CubicWeb source code
-
def _cw_cnx(request)
ofcubicweb/pyramid/core.py
-
Session.new_cnx
ofcubicweb/pyramid/core.py
-
Connection
(with goodsession._cached_lang
and soself.lang
) ofcubicweb/pyramid/core.py
-
Connection
ofcubicweb/server/session.py
# cubicweb/req.py
def set_language(self, lang):
"""install i18n configuration for `lang` translation.
Raises :exc:`KeyError` if translation doesn't exist.
"""
self.lang = lang
try:
gettext, pgettext = self.vreg.config.translations[lang]
except KeyError:
assert self.vreg.config.mode == 'test'
gettext = text_type
def pgettext(x, y):
return text_type(y)
# use _cw.__ to translate a message without registering it to the catalog
self._ = self.__ = gettext
self.pgettext = pgettext
Edited by Nicola Spanti