让报表支持翻译

来自Odoo大V社-odoo中文开发手册
跳转至: 导航搜索

要为报表启用翻译,需要使用<t t-call>标签的t-lang属性从另一个模板中调用。

t-lang属性应该设置为一个语言代码的具体值,比如 es 或 en_US。它需要可以找到使用语言的字段的名称。这通常是合作伙伴中的partner_id.lang字段。在我们的案例中,我们没有合作伙伴,但我们可以,使用用户,相应的语言首选项在user_id.lang字段中

该函需要一个模板名称来呈现和翻译它。这意味着我们需要将报告的页面内容单独定义一个模板,如下所示。

 <report id="action_todo_task_report_translated" 
   string="Translated To-do Tasks" 
   model="todo.task" 
   report_type="qweb-pdf" 
   name="todo_report.report_todo_task_translated" 
   paperformat="paperformat_euro_landscape" 
 /> 
 <template id="report_todo_task_translated"> 
   <t t-call="todo_report.report_todo_task_template" 
     t-lang="user.lang" > 
     <t t-set="docs" 
       t-value="docs" /> 
     </t> 
   </t> 
 </template>