Skip to Content
Menu
This question has been flagged
2 Replies
3261 Views
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!

Avatar
Discard
Best Answer

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


Avatar
Discard
Best Answer

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


Avatar
Discard
Related Posts Replies Views Activity
3
Sep 24
1315
0
Dec 23
1271
1
Nov 24
39467
0
Oct 21
2865
1
Jul 21
3604