diff --git a/trytond/CHANGELOG b/trytond/CHANGELOG index 411940bb16..6548efa6b4 100644 --- a/trytond/CHANGELOG +++ b/trytond/CHANGELOG @@ -1,3 +1,4 @@ +* Support plural translations in report * Add plural source to translations * Add plural to language * Set Decimal precision of default context from TRYTOND_DECIMAL_PREC diff --git a/trytond/trytond/report/report.py b/trytond/trytond/report/report.py index 61a8f673b8..924dd20a6b 100644 --- a/trytond/trytond/report/report.py +++ b/trytond/trytond/report/report.py @@ -127,9 +127,13 @@ class TranslateFactory: self.report_name = report_name self.translation = translation - def __call__(self, text): + def gettext(self, text): return self.translation.get_report(self.report_name, text) + def ngettext(self, text, text_plural, n): + return self.translation.get_report( + self.report_name, text, text_plural, n) + class Report(URLMixin, PoolBase): @@ -373,12 +377,13 @@ class Report(URLMixin, PoolBase): pool = Pool() Translation = pool.get('ir.translation') translate = TranslateFactory(cls.__name__, Translation) - translator = Translator(lambda text: translate(text)) + translator = Translator(translate) # Do not use Translator.setup to add filter at the end # after set_lang evaluation template.filters.append(translator) if hasattr(template, 'add_directives'): template.add_directives(Translator.NAMESPACE, translator) + return translate @classmethod def render(cls, report, report_context): @@ -390,7 +395,11 @@ class Report(URLMixin, PoolBase): klass = loader.factories[loader.get_type(mimetype)] template = klass(BytesIO(report.report_content)) report.set_template_cached(template) - cls._callback_loader(report, template) + translate = cls._callback_loader(report, template) + if translate: + report_context = report_context.copy() + report_context['gettext'] = translate.gettext + report_context['ngettext'] = translate.ngettext data = template.generate(**report_context).render() if hasattr(data, 'getvalue'): data = data.getvalue()