[FIX] core: write terms to en_US if not activated
Before this commit: when en_US is not activated and the user changes terms slightly for ir.ui.view.arch, the new term will be treated as a typo fix or style change, and won't be populated to other languages. As a result, in the form view, arch_base field which displays the en_US translation of the arch_db will still be the content before the change(wrong and strange). After this commit: when write a model_terms field when en_US is not activated, its en_US value will always be overwritten. opw-3265418 closes odoo/odoo#122006 X-original-commit: e7fd2361ab83f3a02ada09c18094adc5c7517227 Signed-off-by: Raphael Collet <rco@odoo.com> Signed-off-by: Wang Chong (cwg) <cwg@odoo.com>
This commit is contained in:
@@ -976,6 +976,31 @@ class TestXMLTranslation(TransactionCase):
|
||||
self.assertEqual(view.with_env(env_fr).arch_db, archf % (terms_en[0], terms_fr[1]))
|
||||
self.assertEqual(view.with_env(env_nl).arch_db, archf % (terms_en[0], terms_nl[1]))
|
||||
|
||||
def test_sync_xml_no_en(self):
|
||||
self.env['res.lang']._activate_lang('fr_FR')
|
||||
self.env['res.lang']._activate_lang('nl_NL')
|
||||
|
||||
archf = '<form string="X">%s<div>%s</div></form>'
|
||||
terms_en = ('Bread and cheese', 'Fork')
|
||||
terms_fr = ('Pain et fromage', 'Fourchetta')
|
||||
terms_nl = ('Brood and kaas', 'Vork')
|
||||
view = self.create_view(archf, terms_en, en_US=terms_en, fr_FR=terms_fr, nl_NL=terms_nl)
|
||||
|
||||
self.env['res.partner'].with_context(active_test=False).search([]).write({'lang': 'fr_FR'})
|
||||
self.env.ref('base.lang_en').active = False
|
||||
|
||||
env_nolang = self.env(context={})
|
||||
env_fr = self.env(context={'lang': 'fr_FR'})
|
||||
env_nl = self.env(context={'lang': 'nl_NL'})
|
||||
|
||||
# style change and typo change
|
||||
terms_fr = ('Pain <span style="font-weight:bold">et</span> fromage', 'Fourchette')
|
||||
view.with_env(env_fr).write({'arch_db': archf % terms_fr})
|
||||
|
||||
self.assertEqual(view.with_env(env_nolang).arch_db, archf % terms_fr)
|
||||
self.assertEqual(view.with_env(env_fr).arch_db, archf % terms_fr)
|
||||
self.assertEqual(view.with_env(env_nl).arch_db, archf % terms_nl)
|
||||
|
||||
def test_sync_xml_collision(self):
|
||||
""" Check translations of 'arch' after xml tags changes in source terms
|
||||
when the same term appears in different elements with different
|
||||
|
||||
+3
-2
@@ -1790,7 +1790,7 @@ class _String(Field):
|
||||
if not old_translations:
|
||||
new_translations_list.append({'en_US': cache_value, lang: cache_value})
|
||||
continue
|
||||
from_lang_value = old_translations.get(lang, old_translations.get('en_US'))
|
||||
from_lang_value = old_translations.get(lang, old_translations['en_US'])
|
||||
translation_dictionary = self.get_translation_dictionary(from_lang_value, old_translations)
|
||||
text2terms = defaultdict(list)
|
||||
for term in new_terms:
|
||||
@@ -1809,7 +1809,8 @@ class _String(Field):
|
||||
for l in old_translations.keys()
|
||||
}
|
||||
new_translations[lang] = cache_value
|
||||
new_translations.setdefault('en_US', cache_value)
|
||||
if not records.env['res.lang']._lang_get_id('en_US'):
|
||||
new_translations['en_US'] = cache_value
|
||||
new_translations_list.append(new_translations)
|
||||
# Maybe we can use Cache.update(records.with_context(cache_update_raw=True), self, new_translations_list, dirty=True)
|
||||
cache.update_raw(records, self, new_translations_list, dirty=True)
|
||||
|
||||
Reference in New Issue
Block a user