From eb90eb42ce5ddbdbc1f64218feb70b1921d5a9a3 Mon Sep 17 00:00:00 2001 From: "Moises Lopez - https://www.vauxoo.com/" Date: Tue, 21 Nov 2017 10:56:28 -0600 Subject: [PATCH] [IMP] translate: export empty translations for empty ones Instead of use the original string by default. Currently odoo export a PO translation file using the logic: "If there is not a translation then use the source." This generate a false 100% of file translated for tools based on PO files. This commit change this logic to: "If there is not a translation then use empty string." Odoo import a PO translation file supporting empty string because if a item is empty string odoo use the original source. Closes #17925 --- odoo/addons/base/ir/ir_translation.py | 3 -- .../tests/test_term_count.py | 35 +++++++++++++++++++ odoo/tools/translate.py | 2 +- 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/odoo/addons/base/ir/ir_translation.py b/odoo/addons/base/ir/ir_translation.py index f77d84e758b..148e360f3ac 100644 --- a/odoo/addons/base/ir/ir_translation.py +++ b/odoo/addons/base/ir/ir_translation.py @@ -55,9 +55,6 @@ class IrTranslationImport(object): def push(self, trans_dict): """ Feed a translation, as a dictionary, into the cursor """ - if not trans_dict['value']: - return - params = dict(trans_dict, state="translated") if params['type'] == 'view': diff --git a/odoo/tests/addons/test_translation_import/tests/test_term_count.py b/odoo/tests/addons/test_translation_import/tests/test_term_count.py index 864c4222962..8011338cee7 100644 --- a/odoo/tests/addons/test_translation_import/tests/test_term_count.py +++ b/odoo/tests/addons/test_translation_import/tests/test_term_count.py @@ -1,8 +1,16 @@ # -*- coding: utf-8 -*- +from contextlib import closing + import odoo from odoo.tests import common +try: + from StringIO import StringIO +except ImportError: + from io import StringIO + + class TestTermCount(common.TransactionCase): def test_count_term(self): @@ -30,3 +38,30 @@ class TestTermCount(common.TransactionCase): menu.refresh() self.assertEqual(menu.name, "New Name") self.assertEqual(menu.with_context(lang='fr_FR').name, "Nouveau nom") + + def test_export_empty_string(self): + """When the string and the translation is equal the translation is empty""" + # Export the translations + def update_translations(): + with closing(StringIO()) as bufferobj: + odoo.tools.trans_export('fr_FR', ['test_translation_import'], bufferobj, 'po', self.cr) + bufferobj.name = 'test_translation_import/i18n/fr.po' + odoo.tools.trans_load_data(self.cr, bufferobj, 'po', 'fr_FR', verbose=False, context={'overwrite': True}) + + # Check if the not translated key is empty string + update_translations() + translation = self.env['ir.translation'].search_count([('src', '=', 'Efgh'), ('value', '=', '')]) + self.assertTrue(translation, 'The translation of "Efgh" should be empty') + + # Modify the value translated for the equal value of the key + menu = self.env.ref('test_translation_import.menu_test_translation_import') + menu.name = "New Name" + menu.with_context(lang='fr_FR').name = "New Name" + update_translations() + self.assertEqual(menu.with_context(lang='fr_FR').name, "New Name", 'The translation of "New Name" should be "New Name"') + + # Modify the value translated for another different value + menu.name = "New Name" + menu.with_context(lang='fr_FR').name = "Nouveau nom" + update_translations() + self.assertEqual(menu.with_context(lang='fr_FR').name, "Nouveau nom", 'The translation of "New Name" should be "Nouveau nom"') diff --git a/odoo/tools/translate.py b/odoo/tools/translate.py index 8ffb9fc06af..4690bd142f1 100644 --- a/odoo/tools/translate.py +++ b/odoo/tools/translate.py @@ -683,7 +683,7 @@ def trans_export(lang, modules, buffer, format, cr): # translation template, so no translation value row['translation'] = '' elif not row.get('translation'): - row['translation'] = src + row['translation'] = '' writer.write(row['modules'], row['tnrs'], src, row['translation'], row['comments']) elif format == 'tgz':