コンテンツへスキップ
メニュー
この質問にフラグが付けられました
1 返信
6734 ビュー

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
3月 15
4410
2
6月 25
2274
4
5月 24
6237
1
5月 23
4004
2
1月 18
7813