diff --git a/odoo/tools/translate.py b/odoo/tools/translate.py index b2bf929ec18..c1cd7d305ed 100644 --- a/odoo/tools/translate.py +++ b/odoo/tools/translate.py @@ -508,14 +508,25 @@ class _lt: works as expected (unlike the classic GettextAlias implementation). """ - __slots__ = ['_source'] - def __init__(self, source): + __slots__ = ['_source', '_args'] + def __init__(self, source, *args, **kwargs): self._source = source + assert not (args and kwargs) + self._args = args or kwargs def __str__(self): # Call _._get_translation() like _() does, so that we have the same number # of stack frames calling _get_translation() - return _._get_translation(self._source) + translation = _._get_translation(self._source) + if self._args: + try: + return translation % self._args + except (TypeError, ValueError, KeyError): + bad = translation + # fallback: apply to source before logging exception (in case source fails) + translation = self._source % self._args + _logger.exception('Bad translation %r for string %r', bad, self._source) + return translation def __eq__(self, other): """ Prevent using equal operators