From 16336ffeae7fb145b376774d3e094dbcb786f3c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sat, 5 Nov 2016 19:59:51 +0100 Subject: [PATCH] Support derivative translations in reports TranslateFactory must search throw all parents languages. issue6012 review30751003 --- trytond/report/report.py | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/trytond/report/report.py b/trytond/report/report.py index ec7a358ac4..8ce19bcf1f 100644 --- a/trytond/report/report.py +++ b/trytond/report/report.py @@ -19,6 +19,7 @@ from trytond.transaction import Transaction from trytond.url import URLMixin from trytond.rpc import RPC from trytond.exceptions import UserError +from trytond.tools import get_parent_language MIMETYPES = { 'odt': 'application/vnd.oasis.opendocument.text', @@ -72,18 +73,21 @@ class TranslateFactory: def __call__(self, text): if self.language not in self.cache: - self.cache[self.language] = {} - translations = self.translation.search([ - ('lang', '=', self.language), - ('type', '=', 'report'), - ('name', '=', self.report_name), - ('value', '!=', ''), - ('value', '!=', None), - ('fuzzy', '=', False), - ('res_id', '=', -1), - ]) - for translation in translations: - self.cache[self.language][translation.src] = translation.value + cache = self.cache[self.language] = {} + code = self.language + while code: + translations = self.translation.search([ + ('lang', '=', code), + ('type', '=', 'report'), + ('name', '=', self.report_name), + ('value', '!=', ''), + ('value', '!=', None), + ('fuzzy', '=', False), + ('res_id', '=', -1), + ]) + for translation in translations: + cache.setdefault(translation.src, translation.value) + code = get_parent_language(code) return self.cache[self.language].get(text, text) def set_language(self, language):