تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
1 الرد
6711 أدوات العرض

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 ;-)

الصورة الرمزية
إهمال
أفضل إجابة

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>

 

الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
0
مارس 15
4389
2
يونيو 25
2249
4
مايو 24
6215
1
مايو 23
3994
2
يناير 18
7804