[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: '<form string="X">Bread and cheeze</form>'
                 != '<form string="X">Bread and cheese</form>'

opw-2153422
closes #41714

closes odoo/odoo#41809

X-original-commit: 7eb603b26cc591b85ceb11210f5db8308d2ba27a
Signed-off-by: Nicolas Lempereur (nle) <nle@odoo.com>
This commit is contained in:
Nicolas Lempereur
2019-12-12 12:23:09 +00:00
parent 2cc8316c66
commit 200045d337
2 changed files with 8 additions and 1 deletions
+4 -1
View File
@@ -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
+4
View File
@@ -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)