diff options
| author | Martin Trigaux <mat@odoo.com> | 2019-11-26 11:10:51 +0000 |
|---|---|---|
| committer | Martin Trigaux <mat@odoo.com> | 2019-11-28 11:43:46 +0000 |
| commit | b175558ce72f3f8f0badaa17613dbcbeb93f503c (patch) | |
| tree | 00c1f022171444435d42a21e05a449da016c2783 /odoo/tools | |
| parent | 9725eadfdd9728b938b345c81e1da80c51e64c65 (diff) | |
[FIX] tools: no pollution during export translation
Before this commit, the export of translations was incorrect for code
and model translations:
For code translations, the field 'name' was used for the matching
while the _() method explicitly use None in the _get_source call to
only use the field 'src' for the search.
For model translations, the field 'res_id' was not used when searching
for a translation.
For instance, if a ir.model.fields did not have translated label,
exporting the translations was using the translations of the first
field having the same source.
While this could be convient during the import (to be discussed),
doing so in an export of translation is clearly an unexpected
side-effect.
closes odoo/odoo#40909
X-original-commit: 4534181f106cf5aa50c65c942c260eeec122d3d2
Signed-off-by: Martin Trigaux (mat) <mat@odoo.com>
Diffstat (limited to 'odoo/tools')
| -rw-r--r-- | odoo/tools/translate.py | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/odoo/tools/translate.py b/odoo/tools/translate.py index 1a96b8f192e..f8a4be823aa 100644 --- a/odoo/tools/translate.py +++ b/odoo/tools/translate.py @@ -903,11 +903,22 @@ class TranslationModuleReader: """ Export ir.translation values for all retrieved records """ IrTranslation = self.env['ir.translation'] - for module, source, name, res_id, ttype, comments in self._to_translate: - trans = IrTranslation._get_source(name, ttype, self._lang, source) if self._lang else "" + for module, source, name, res_id, ttype, comments, record_id in self._to_translate: + trans = ( + IrTranslation._get_source(name if type != "code" else None, ttype, self._lang, source, res_id=record_id) + if self._lang + else "" + ) yield (module, ttype, name, res_id, source, encode(trans) or '', comments) - def _push_translation(self, module, ttype, name, res_id, source, comments=None): + def _push_translation(self, module, ttype, name, res_id, source, comments=None, record_id=None): + """ Insert a translation that will be used in the file generation + In po file will create an entry + #: <ttype>:<name>:<res_id> + #, <comment> + msgid "<source>" + record_id is the database id of the record being translated + """ # empty and one-letter terms are ignored, they probably are not meant to be # translated, and would be very hard to translate anyway. sanitized_term = (source or '').strip() @@ -915,8 +926,7 @@ class TranslationModuleReader: sanitized_term = re.sub(r'\W+', '', sanitized_term) if not sanitized_term or len(sanitized_term) <= 1: return - - self._to_translate.append((module, source, name, res_id, ttype, tuple(comments or ()))) + self._to_translate.append((module, source, name, res_id, ttype, tuple(comments or ()), record_id)) def _get_translatable_records(self, records): """ Filter the records that are translatable @@ -1004,7 +1014,7 @@ class TranslationModuleReader: continue for term in set(field.get_trans_terms(value)): trans_type = 'model_terms' if callable(field.translate) else 'model' - self._push_translation(module, trans_type, name, xml_name, term) + self._push_translation(module, trans_type, name, xml_name, term, record_id=record.id) def _get_module_from_path(self, path): for (mp, rec) in self._path_list: |
