[FIX] translate: lang detection fallback actually falls back
For instance, when a context was passed to a method, but no lang was defined in the context, it did not tried to fallback to other places where we could have find the user language.
This commit is contained in:
parent
de27e19794
commit
1cbf48417e
|
@ -195,16 +195,21 @@ class GettextAlias(object):
|
||||||
def _get_lang(self, frame):
|
def _get_lang(self, frame):
|
||||||
# try, in order: context.get('lang'), kwargs['context'].get('lang'),
|
# try, in order: context.get('lang'), kwargs['context'].get('lang'),
|
||||||
# self.env.lang, self.localcontext.get('lang')
|
# self.env.lang, self.localcontext.get('lang')
|
||||||
if 'context' in frame.f_locals:
|
lang = None
|
||||||
return frame.f_locals['context'].get('lang')
|
if frame.f_locals.get('context'):
|
||||||
|
lang = frame.f_locals['context'].get('lang')
|
||||||
|
if not lang:
|
||||||
kwargs = frame.f_locals.get('kwargs', {})
|
kwargs = frame.f_locals.get('kwargs', {})
|
||||||
if 'context' in kwargs:
|
if kwargs.get('context'):
|
||||||
return kwargs['context'].get('lang')
|
lang = kwargs['context'].get('lang')
|
||||||
|
if not lang:
|
||||||
s = frame.f_locals.get('self')
|
s = frame.f_locals.get('self')
|
||||||
if hasattr(s, 'env'):
|
if hasattr(s, 'env'):
|
||||||
return s.env.lang
|
lang = s.env.lang
|
||||||
|
if not lang:
|
||||||
if hasattr(s, 'localcontext'):
|
if hasattr(s, 'localcontext'):
|
||||||
return s.localcontext.get('lang')
|
lang = s.localcontext.get('lang')
|
||||||
|
if not lang:
|
||||||
# Last resort: attempt to guess the language of the user
|
# Last resort: attempt to guess the language of the user
|
||||||
# Pitfall: some operations are performed in sudo mode, and we
|
# Pitfall: some operations are performed in sudo mode, and we
|
||||||
# don't know the originial uid, so the language may
|
# don't know the originial uid, so the language may
|
||||||
|
@ -213,8 +218,8 @@ class GettextAlias(object):
|
||||||
(cr, dummy) = self._get_cr(frame, allow_create=False)
|
(cr, dummy) = self._get_cr(frame, allow_create=False)
|
||||||
uid = self._get_uid(frame)
|
uid = self._get_uid(frame)
|
||||||
if pool and cr and uid:
|
if pool and cr and uid:
|
||||||
return pool['res.users'].context_get(cr, uid)['lang']
|
lang = pool['res.users'].context_get(cr, uid)['lang']
|
||||||
return None
|
return lang
|
||||||
|
|
||||||
def __call__(self, source):
|
def __call__(self, source):
|
||||||
res = source
|
res = source
|
||||||
|
|
Loading…
Reference in New Issue