From 200045d33779d12147512e47683584ee85c4ddd1 Mon Sep 17 00:00:00 2001 From: Nicolas Lempereur Date: Wed, 11 Dec 2019 12:39:55 +0000 Subject: [PATCH] [FIX] base: update en_US translation on src update On the website when you modified a string with not much change, we modify the translation source so they are not dropped. But we also do it for an en_US translation, so if we have a translation: lang=en_US/src=helloworld/value=helloworld if we change `helloworld` by `helloworld!` the translation would become: lang=en_US/src=helloworld!/value=helloworld which would make it seem like the change did not work at all. Without change, modifed test fail on second: self.assertEqual(view.with_env(env_us).arch_db, archf % terms_en) with assertion: AssertionError: '
Bread and cheeze
' != '
Bread and cheese
' opw-2153422 closes #41714 closes odoo/odoo#41809 X-original-commit: 7eb603b26cc591b85ceb11210f5db8308d2ba27a Signed-off-by: Nicolas Lempereur (nle) --- odoo/addons/base/models/ir_translation.py | 5 ++++- odoo/addons/base/tests/test_translate.py | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/odoo/addons/base/models/ir_translation.py b/odoo/addons/base/models/ir_translation.py index a133758c2c1..938543ce456 100644 --- a/odoo/addons/base/models/ir_translation.py +++ b/odoo/addons/base/models/ir_translation.py @@ -437,7 +437,10 @@ class IrTranslation(models.Model): elif (src, translation.lang) in done: discarded += translation else: - translation.write({'src': src, 'state': translation.state}) + vals = {'src': src, 'state': translation.state} + if translation.lang == 'en_US': + vals['value'] = src + translation.write(vals) done.add((src, translation.lang)) # process outdated and discarded translations diff --git a/odoo/addons/base/tests/test_translate.py b/odoo/addons/base/tests/test_translate.py index 0d421842e0d..981d826cfd4 100644 --- a/odoo/addons/base/tests/test_translate.py +++ b/odoo/addons/base/tests/test_translate.py @@ -652,19 +652,23 @@ class TestXMLTranslation(TransactionCase): view = self.create_view(archf, terms_en, fr_FR=terms_fr, nl_NL=terms_nl) env_en = self.env(context={}) + env_us = self.env(context={'lang': 'en_US'}) env_fr = self.env(context={'lang': 'fr_FR'}) env_nl = self.env(context={'lang': 'nl_NL'}) self.assertEqual(view.with_env(env_en).arch_db, archf % terms_en) + self.assertEqual(view.with_env(env_us).arch_db, archf % terms_en) self.assertEqual(view.with_env(env_fr).arch_db, archf % terms_fr) self.assertEqual(view.with_env(env_nl).arch_db, archf % terms_nl) # modify source term in view (fixed type in 'cheeze') terms_en = ('Bread and cheese',) view.write({'arch_db': archf % terms_en}) + view.invalidate_cache(fnames=['arch_db'], ids=view.ids) # check whether translations have been synchronized self.assertEqual(view.with_env(env_en).arch_db, archf % terms_en) + self.assertEqual(view.with_env(env_us).arch_db, archf % terms_en) self.assertEqual(view.with_env(env_fr).arch_db, archf % terms_fr) self.assertEqual(view.with_env(env_nl).arch_db, archf % terms_nl)