hi there, if it is to any interest for someone, here is a little patch (3-liner) to reuse translation context from a custom report to inherit from... given the property >> __translation_context__ = (__name__, superclass.__name__, ...) << translation is used from class first and superclass andsoon...
best regards, thanks for the cool tool! simon
>From fe23c49ee529c929ea0fdd19fdb9c6cc4b538bcd Mon Sep 17 00:00:00 2001 From: hiaselhans <si...@booya.at> Date: Wed, 5 Mar 2014 20:09:27 +0100 Subject: [PATCH] report translation_context inheritance --- trytond/report/report.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/trytond/report/report.py b/trytond/report/report.py index 42a6d5d..5fcd83d 100644 --- a/trytond/report/report.py +++ b/trytond/report/report.py @@ -75,17 +75,20 @@ 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', '=', 'odt'), - ('name', '=', self.report_name), - ('value', '!=', ''), - ('value', '!=', None), - ('fuzzy', '=', False), - ('res_id', '=', -1), - ]) + translations = [] + for name in self.report_name: + translations += self.translation.search([ + ('lang', '=', self.language), + ('type', '=', 'odt'), + ('name', '=', name), + ('value', '!=', ''), + ('value', '!=', None), + ('fuzzy', '=', False), + ('res_id', '=', -1), + ]) for translation in translations: - self.cache[self.language][translation.src] = translation.value + if not translation.src in self.cache[self.language]: + self.cache[self.language][translation.src] = translation.value return self.cache[self.language].get(text, text) def set_language(self, language): @@ -93,6 +96,7 @@ class TranslateFactory: class Report(URLMixin, PoolBase): + __translation_context__ = None @classmethod def __setup__(cls): @@ -174,7 +178,7 @@ class Report(URLMixin, PoolBase): localcontext['datetime'] = datetime localcontext['context'] = Transaction().context - translate = TranslateFactory(cls.__name__, Transaction().language, + translate = TranslateFactory(cls.__translation_context__ or (cls.__name__,), Transaction().language, Translation) localcontext['setLang'] = lambda language: translate.set_language( language) -- 1.9.0