[FIX] tools: do not translate selections with _translate=False

If a model is tagged with _translate=False, it should not be translated.
A special case was made for ir.model.fields but not ir.model.fields.selection

Before this commit, the selections of web_editor.converter.test were translated

closes odoo/odoo#36576

Signed-off-by: Martin Trigaux (mat) <mat@odoo.com>
This commit is contained in:
Martin Trigaux
2019-09-09 14:57:15 +00:00
parent 5d2021e79f
commit 19e50ea374
2 changed files with 18 additions and 36 deletions
-20
View File
@@ -923,11 +923,6 @@ msgstr ""
msgid "Keyboard shortcuts"
msgstr ""
#. module: web_editor
#: model:ir.model.fields.selection,name:web_editor.selection__web_editor_converter_test__selection_str__d
msgid "La réponse D"
msgstr ""
#. module: web_editor
#. openerp-web
#: code:addons/web_editor/static/src/js/editor/rte.summernote.js:0
@@ -1165,21 +1160,6 @@ msgstr ""
msgid "Preview"
msgstr ""
#. module: web_editor
#: model:ir.model.fields.selection,name:web_editor.selection__web_editor_converter_test__selection_str__c
msgid "Qu'est-ce qu'il fout ce maudit pancake, tabernacle ?"
msgstr ""
#. module: web_editor
#: model:ir.model.fields.selection,name:web_editor.selection__web_editor_converter_test__selection_str__a
msgid "Qu'il n'est pas arrivé à Toronto"
msgstr ""
#. module: web_editor
#: model:ir.model.fields.selection,name:web_editor.selection__web_editor_converter_test__selection_str__b
msgid "Qu'il était supposé arriver à Toronto"
msgstr ""
#. module: web_editor
#. openerp-web
#: code:addons/web_editor/static/src/xml/wysiwyg.xml:0
+18 -16
View File
@@ -890,6 +890,21 @@ def trans_generate(lang, modules, cr):
tnx = (module, source, name, id, type, tuple(comments or ()))
to_translate.add(tnx)
def translatable_model(record):
if not record._translate:
return False
if record._name == 'ir.model.fields.selection':
record = record.field_id
if record._name == 'ir.model.fields':
field_name = record.name
field_model = env.get(record.model)
if (field_model is None or not field_model._translate or
field_name not in field_model._fields):
return False
return True
query = 'SELECT min(name), model, res_id, module FROM ir_model_data'
if 'all_installed' in modules:
@@ -914,25 +929,12 @@ def trans_generate(lang, modules, cr):
continue
record = env[model].browse(res_id)
if not record._translate:
# explicitly disabled
continue
if not record.exists():
_logger.warning(u"Unable to find object %r with id %d", model, res_id)
continue
return False
if model==u'ir.model.fields':
try:
field_name = record.name
except AttributeError as exc:
_logger.error(u"name error in %s: %s", xml_name, str(exc))
continue
field_model = env.get(record.model)
if (field_model is None or not field_model._translate or
field_name not in field_model._fields):
continue
field = field_model._fields[field_name]
if not translatable_model(record):
continue
for field_name, field in record._fields.items():
if field.translate: