summaryrefslogtreecommitdiff
path: root/odoo/tools/translate.py
diff options
context:
space:
mode:
authorMartin Trigaux <mat@odoo.com>2020-06-29 15:04:11 +0000
committerMartin Trigaux <mat@odoo.com>2020-06-30 10:19:50 +0000
commit110263df56933abe885d1c4058afa5a0669e5aa9 (patch)
treecc188b345a9784d9825390c0154ca822b9667782 /odoo/tools/translate.py
parentd12813f7eec9d71be7573bf1dcaba9f8cf67eb79 (diff)
[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
Diffstat (limited to 'odoo/tools/translate.py')
-rw-r--r--odoo/tools/translate.py17
1 files changed, 14 insertions, 3 deletions
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