Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
2 Odpovědi
3269 Zobrazení
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
Zrušit
Nejlepší odpověď

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
Zrušit
Nejlepší odpověď

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
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
3
zář 24
1317
0
pro 23
1273
1
lis 24
39474
0
říj 21
2872
1
čvc 21
3610