跳至内容
菜单
此问题已终结
2 回复
3277 查看
name = fields.Char('Name', index=True, required=True, translate=True)
nameUA = fields.Char('Name Ua', compute='_compute_name_ukr', inverce='_inverse_name_ukr', readonly=False)
def _compute_name_ukr(self):
for obj in self:
obj.nameUA = obj.with_context(lang='uk_UA').name
def _inverse_name_ukr(self):
for obj in self:
obj.with_context(lang='uk_UA').name = obj.nameUA
@api.onchange('nameUA')
def onchange_name_ukr(self):
for obj in self:
obj.with_context(lang='uk_UA').name = obj.nameUA


Thanks to this code, I get the translation of the field in Ukrainian, but if I change the field with the translation, the translation does not change, what am I doing wrong?

thanks!

形象
丢弃
最佳答案

I don't know if it is still required, but your coding should be as follow

nameUA = fields.Char('Name Ua', compute='_compute_name_ukr', inverse='_inverse_name_ukr', readonly=False)

notice the letter "s" in the inverse method, not as typed here with a "c"


i am not sure if it matters, but onchange normally applies to a single record so your onchange method should be

@api.onchange('nameUA')
def onchange_name_ukr(self):
self.with_context(lang='uk_UA').name = self.nameUA


形象
丢弃
最佳答案

Follow below steps:

1) Go to

Settings ‣ Translations ‣ Import / Export ‣ Export Translations

leave the language to the default (new language/empty template) # DO NOT CHANGE THIS

select the PO File format

select your module

click Export and download the file

2) Add your translation terms in the downloaded file. i.e. msgstr "" section depending on your translation language

3) change the filename to language_iso_code.po

e.g. for portugese => pt.po

4) create i18n folder under your module and add po file in it.

5) restart Odoo

6) Go to:

Settings ‣ Translations ‣ Load a Translation

select translation language (in my eg. Portugese)

make sure you check this : Overwrite Existing Terms

click LOAD.

DONE


形象
丢弃
相关帖文 回复 查看 活动
3
9月 24
1318
0
12月 23
1274
1
11月 24
39481
0
10月 21
2876
1
7月 21
3614