diff --git a/odoo/addons/test_translation_import/tests/test_term_count.py b/odoo/addons/test_translation_import/tests/test_term_count.py index bde7bceac4f..936a9c93c61 100644 --- a/odoo/addons/test_translation_import/tests/test_term_count.py +++ b/odoo/addons/test_translation_import/tests/test_term_count.py @@ -23,6 +23,18 @@ class TestTermCount(common.TransactionCase): ]) self.assertEqual(len(ids), 2) + def test_count_term_module(self): + """ + Just make sure we have as many translation entries as we wanted and module deducted from file content + """ + odoo.tools.trans_load(self.cr, 'test_translation_import/i18n/fr.po', 'fr_FR', verbose=False) + translations = self.env['ir.translation'].search([ + ('lang', '=', 'fr_FR'), + ('src', '=', 'Ijkl'), + ('module', '=', 'test_translation_import'), + ]) + self.assertEqual(len(translations), 1) + def test_noupdate(self): """ Make sure no update do not overwrite translations diff --git a/odoo/tools/translate.py b/odoo/tools/translate.py index 458d5ff6c3f..e9df23d6bb5 100644 --- a/odoo/tools/translate.py +++ b/odoo/tools/translate.py @@ -509,7 +509,7 @@ class PoFile(object): return self.lines_count - len(self.lines) def next(self): - trans_type = name = res_id = source = trad = None + trans_type = name = res_id = source = trad = module = None if self.extra_lines: trans_type, name, res_id, source, trad, comments = self.extra_lines.pop(0) if not res_id: @@ -530,6 +530,8 @@ class PoFile(object): line = line[2:].strip() if not line.startswith('module:'): comments.append(line) + else: + module = line[7:].strip() elif line.startswith('#:'): # Process the `reference` comments. Each line can specify # multiple targets (e.g. model, view, code, selection, @@ -603,7 +605,7 @@ class PoFile(object): _logger.warning('Missing "#:" formatted comment at line %d for the following source:\n\t%s', self.cur_line(), source[:30]) return next(self) - return trans_type, name, res_id, source, trad, '\n'.join(comments) + return trans_type, name, res_id, source, trad, '\n'.join(comments), module __next__ = next def write_infos(self, modules): @@ -1045,7 +1047,7 @@ def trans_load_data(cr, fileobj, fileformat, lang, lang_name=None, verbose=True, elif fileformat == 'po': reader = PoFile(fileobj) - fields = ['type', 'name', 'res_id', 'src', 'value', 'comments'] + fields = ['type', 'name', 'res_id', 'src', 'value', 'comments', 'module'] # Make a reader for the POT file and be somewhat defensive for the # stable branch. @@ -1079,7 +1081,7 @@ def trans_load_data(cr, fileobj, fileformat, lang, lang_name=None, verbose=True, self.comments = None pot_targets = defaultdict(Target) - for type, name, res_id, src, _ignored, comments in pot_reader: + for type, name, res_id, src, _ignored, comments, module in pot_reader: if type is not None: target = pot_targets[src] target.targets.add((type, name, type != 'code' and res_id or 0))