Skip to content

Commit 4133952

Browse files
committed
[FIX] core: fix typofix translation
The get_text_content is not powerful enough to extract translated attributes. As a result, get_text_content will return empty string '' for terms whose translated contents are only in attributes. When the result is used to build the mapping text2terms, users will get strange result after write. opw-4147913 closes odoo#193574 Signed-off-by: Raphael Collet <rco@odoo.com>
1 parent 4375971 commit 4133952

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

odoo/addons/base/tests/test_translate.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -997,6 +997,20 @@ def test_sync_xml_no_en(self):
997997
self.assertEqual(view.with_env(env_fr).arch_db, archf % terms_fr)
998998
self.assertEqual(view.with_env(env_nl).arch_db, archf % terms_nl)
999999

1000+
def test_sync_xml_attribute(self):
1001+
""" check translations with attribute can be cleaned up after write """
1002+
self.env['res.lang']._activate_lang('fr_FR')
1003+
archf = '<form><i title="%s"/></form>'
1004+
terms_en = ('Fork',)
1005+
terms_fr = ('Fourchetta',)
1006+
view = self.create_view(archf, terms_en, en_US=terms_en, fr_FR=terms_fr)
1007+
1008+
terms_en = ('Cheese',)
1009+
view.write({'arch_db': archf % terms_en})
1010+
1011+
self.assertEqual(view.arch_db, archf % terms_en)
1012+
self.assertEqual(view.with_context(lang='fr_FR').arch_db, archf % terms_en)
1013+
10001014
def test_sync_text_to_xml(self):
10011015
""" Check translations of 'arch' after xml tags changes in source terms. """
10021016
archf = '<form string="X">%s</form>'

odoo/fields.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1815,7 +1815,9 @@ def write(self, records, value):
18151815
translation_dictionary = self.get_translation_dictionary(from_lang_value, old_translations)
18161816
text2terms = defaultdict(list)
18171817
for term in new_terms:
1818-
text2terms[self.get_text_content(term)].append(term)
1818+
term_text = self.get_text_content(term)
1819+
if term_text:
1820+
text2terms[term_text].append(term)
18191821

18201822
for old_term in list(translation_dictionary.keys()):
18211823
if old_term not in new_terms:

0 commit comments

Comments
 (0)