Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
2 Odpowiedzi
3273 Widoki
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!

Awatar
Odrzuć
Najlepsza odpowiedź

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


Awatar
Odrzuć
Najlepsza odpowiedź

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


Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
3
wrz 24
1317
0
gru 23
1273
1
lis 24
39476
0
paź 21
2873
1
lip 21
3611