This question has been flagged

Hi there,

I would like to use two languages in one report (invoice). Not for every line, but only for the product name.

I know I have to use setLang but somehow I can't get it to work correctly. The whole report is made up in the language of the client [[ setLang(o.partner_id.lang) ]]. But we would like to have the name of the product in English and Chinese.

This is (a little part of) what I have till now.

<td>
  <para style="terp_default_9">[[ setLang('zh_CN') ]] [[ format(l.product_id.name) ]]</para>
</td>
<td>
  <para style="terp_default_9">[[ setLang('en_US') ]] [[ format(l.product_id.name) ]]</para>
</td>

I will send a big hug to the one who is able to help me ;-)

Avatar
Discard
Best Answer

def translation(self,name,lang=''zh_CN'',source_type=''):

    if source_type:
        query = "select value from ir_translation where lang='"+lang+"' and type='"+source_type+"' and src='"+name+"'"
    else:
        query = "select value from ir_translation where lang='"+lang+"' and src='"+name+"'"
    cr = self.cr
    cr.execute(str(query))
    res_trans = cr.fetchone()
    res = res_trans and res_trans[0] or name
    return res
              
def __init__(self, cr, uid, name, context):

    super(contract, self).__init__(cr, uid, name, context)
    self.cr = cr # re initialize cr
    self.localcontext.update({
            'time': time,
            'translate': self.translation
        })

<td>
  <para style="terp_default_9">[[ translate(format(l.product_id.name)) ]]</para>
</td>

or

<td>
  <para style="terp_default_9">[[translate(format(l.product_id.name),'en_US') ]]</para>
</td>

 

Avatar
Discard