Ir al contenido
Menú
Se marcó esta pregunta
2 Respuestas
3268 Vistas
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
Descartar
Mejor respuesta

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
Descartar
Mejor respuesta

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
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
3
sept 24
1317
0
dic 23
1272
1
nov 24
39474
0
oct 21
2872
1
jul 21
3610