تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
2 الردود
4362 أدوات العرض

Please to not send me links to .po files or to documentation on how to do it through the interface etc. This is only the question: how to do it through python code in Odoo 16? I would love the following to work, but it does not work in Odoo 16, or it does not work with HTML fields. Whatever I do, all previously translated terms are replaced when I set a new value of translatable field in python code.


en_term = "invoice"
es_term = "factura"

record.with_context(lang="en_US").name = en_term
record.with_context(lang="es_ES").name = es_term


It's weird, I can read a term in a language (name = record.with_context(lang="es_ES").name), replace a letter (e.i. "a" by "o"), write it back, and it will override/remove *all* other translations and replace the term just with the newly modified one!


Is there any way to work around this? Any help appreciated.

الصورة الرمزية
إهمال
الكاتب أفضل إجابة

I found an answer myself. Here is how to achieve this in Odoo 16:

field_name = {the field name in question}
lang = {the language you want to update}
new_content = {the new content you want to set}

field = record._fields[field_name]
translations = field._get_stored_translations(record)
translations[lang] = new_content

record.env.cache.update_raw(
record, field, [translations], dirty=True
)
record.modified([field_name])

Keep in mind (for HTML-Fields): this will not update single terms, but the whole content. Exactly what we were looking for.

If there is a more straight forward solution, please, do not hesitate to share it.

الصورة الرمزية
إهمال
أفضل إجابة

Bro, I had the same thing, I didn't know what to do while I was solving this problem, I used custom translations, and I want to tell you that it's not a bad thing. It takes the same amount of time as the translation I did myself, but I don't have to worry about it crashing and not responding, and I don't have to worry about them doing everything accurately. So try it and see how you like it.

الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
3
فبراير 23
4457
Odoo 16 تم الحل
1
ديسمبر 22
3614
8
يناير 25
5796
3
مارس 24
2280
1
فبراير 24
1140