[IMP] tools: use same syntax for _lt than _

A new gettext syntax was added at odoo/odoo#52155 but only for _, not
for _lt
Allow to have the same syntax
This commit is contained in:
Martin Trigaux
2020-06-30 10:19:50 +00:00
parent d12813f7ee
commit 110263df56
+14 -3
View File
@@ -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