[FIX] core: fix translation typo fixing
for model_terms translated fields, for sake of typo fixing feature if a term is removed after write its translations might be reused by another close term which has totally different meaning this fix removes the typo fixing if the matched closest term exists before write closes odoo/odoo#155476 X-original-commit: 38ec36e9b5dde0c02a4ff47714b1056e0db76812 Signed-off-by: Raphael Collet <rco@odoo.com> Signed-off-by: Chong Wang (cwg) <cwg@odoo.com>
This commit is contained in:
@@ -1157,6 +1157,30 @@ class TestXMLTranslation(TransactionCase):
|
||||
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_close_terms(self):
|
||||
""" Check translations of 'arch' after xml tags changes in source terms. """
|
||||
archf = '<form string="X">%s<div>%s</div>%s</form>'
|
||||
terms_en = ('RandomRandom1', 'RandomRandom2', 'RandomRandom3')
|
||||
terms_fr = ('RandomRandom1', 'AléatoireAléatoire2', 'AléatoireAléatoire3')
|
||||
view = self.create_view(archf, terms_en, en_US=terms_en, fr_FR=terms_fr)
|
||||
|
||||
env_nolang = self.env(context={})
|
||||
env_en = self.env(context={'lang': 'en_US'})
|
||||
env_fr = self.env(context={'lang': 'fr_FR'})
|
||||
|
||||
self.assertEqual(view.with_env(env_nolang).arch_db, archf % terms_en)
|
||||
self.assertEqual(view.with_env(env_en).arch_db, archf % terms_en)
|
||||
self.assertEqual(view.with_env(env_fr).arch_db, archf % terms_fr)
|
||||
|
||||
# modify source term in view
|
||||
terms_en = ('RandomRandom1', 'SomethingElse', 'RandomRandom3')
|
||||
view.with_env(env_en).write({'arch_db': archf % terms_en})
|
||||
|
||||
# check whether close terms have correct translations
|
||||
self.assertEqual(view.with_env(env_nolang).arch_db, archf % terms_en)
|
||||
self.assertEqual(view.with_env(env_en).arch_db, archf % terms_en)
|
||||
self.assertEqual(view.with_env(env_fr).arch_db, archf % ('RandomRandom1', 'SomethingElse', 'AléatoireAléatoire3'))
|
||||
|
||||
def test_cache_consistency(self):
|
||||
view = self.env["ir.ui.view"].create({
|
||||
"name": "test_translate_xml_cache_invalidation",
|
||||
|
||||
@@ -1861,6 +1861,8 @@ class _String(Field):
|
||||
matches = get_close_matches(old_term_text, text2terms, 1, 0.9)
|
||||
if matches:
|
||||
closest_term = get_close_matches(old_term, text2terms[matches[0]], 1, 0)[0]
|
||||
if closest_term in translation_dictionary:
|
||||
continue
|
||||
old_is_text = is_text(old_term)
|
||||
closest_is_text = is_text(closest_term)
|
||||
if old_is_text or not closest_is_text:
|
||||
|
||||
Reference in New Issue
Block a user