From d51e43c117c55c757755034d3be71ea74fec3339 Mon Sep 17 00:00:00 2001 From: Romain Derie Date: Wed, 20 Dec 2023 09:45:46 +0000 Subject: [PATCH] [FIX] website_blog: hint that manual post teasers are not translatable Since its introduction with commit [1], the blog post teaser is not translatable as the field was not set as `translate=True` by mistake. It's not possible sadly in stable to add it since the jsonb introduction for translated fields, as `translate=True` behaves as a DB change. Without a module update, it will crash, trying to set jsonb value in a non jsonb field. A best effort is make here to add a tooltip to hint what's going when in translate mode and clicking on this field text. Note that the field is not marked as translatable, but if people click on it, they will see the tooltip. If we face multiple needs, it might be clever to introduce a new property on field declaration allowing the mark a field as "translate forgotten" so that our builder shows this warning out of the box. Step to reproduce: - Install 2 langs on website - Go to /blog in the main language and enter edit mode - Type something on a blog card below the cover (it should show by default the first few sentences of the blog content) - Go to the alternate language and enter translate mode - The field is not maked as translatable and can't be translated [1]: https://github.com/odoo/odoo/commit/8cc850f3a54f62072d4df99de612f17494ffb123#diff-ae5c21b812e929930064fb93dc919ef1701fd63bae3d9fb306160d01be5629b3R114-R115 opw-3474638 closes odoo/odoo#147287 X-original-commit: abc5e3c119b74691949c7f48d3b7ba1f9fc88626 Signed-off-by: Quentin Smetz (qsm) Signed-off-by: Romain Derie (rde) --- addons/website_blog/__manifest__.py | 1 + addons/website_blog/i18n/website_blog.pot | 9 ++++++++ addons/website_blog/models/__init__.py | 1 + addons/website_blog/models/ir_qweb_fields.py | 17 +++++++++++++++ .../static/src/js/components/translator.js | 21 +++++++++++++++++++ 5 files changed, 49 insertions(+) create mode 100644 addons/website_blog/models/ir_qweb_fields.py create mode 100644 addons/website_blog/static/src/js/components/translator.js diff --git a/addons/website_blog/__manifest__.py b/addons/website_blog/__manifest__.py index 86778defe8f..be034a62aa9 100644 --- a/addons/website_blog/__manifest__.py +++ b/addons/website_blog/__manifest__.py @@ -36,6 +36,7 @@ ], 'website.assets_editor': [ 'website_blog/static/src/js/tours/website_blog.js', + 'website_blog/static/src/js/components/*.js', 'website_blog/static/src/js/systray_items/*.js', ], 'website.backend_assets_all_wysiwyg': [ diff --git a/addons/website_blog/i18n/website_blog.pot b/addons/website_blog/i18n/website_blog.pot index 555bd24ce57..5417cfd6c25 100644 --- a/addons/website_blog/i18n/website_blog.pot +++ b/addons/website_blog/i18n/website_blog.pot @@ -1396,6 +1396,15 @@ msgid "" "of what we can see on this our closest space object." msgstr "" +#. module: website_blog +#. odoo-python +#: code:addons/website_blog/models/ir_qweb_fields.py:0 +#, python-format +msgid "" +"On your default language, empty the blog post description and save to get an" +" automated (translated) summary." +msgstr "" + #. module: website_blog #. odoo-javascript #: code:addons/website_blog/static/src/js/tours/website_blog.js:0 diff --git a/addons/website_blog/models/__init__.py b/addons/website_blog/models/__init__.py index 9115ba1be19..e408f7cafc5 100644 --- a/addons/website_blog/models/__init__.py +++ b/addons/website_blog/models/__init__.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. +from . import ir_qweb_fields from . import website from . import website_blog from . import website_snippet_filter diff --git a/addons/website_blog/models/ir_qweb_fields.py b/addons/website_blog/models/ir_qweb_fields.py new file mode 100644 index 00000000000..3b4e64c1636 --- /dev/null +++ b/addons/website_blog/models/ir_qweb_fields.py @@ -0,0 +1,17 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import api, models, _ + + +class Field(models.AbstractModel): + _inherit = 'ir.qweb.field' + + @api.model + def attributes(self, record, field_name, options, values): + attrs = super().attributes(record, field_name, options, values) + + if field_name == 'teaser' and self.env.context.get('edit_translations'): + attrs['data-translate-error-tooltip'] = _("On your default language, empty the blog post description and save to get an automated (translated) summary.") + + return attrs diff --git a/addons/website_blog/static/src/js/components/translator.js b/addons/website_blog/static/src/js/components/translator.js new file mode 100644 index 00000000000..ffde3878f2d --- /dev/null +++ b/addons/website_blog/static/src/js/components/translator.js @@ -0,0 +1,21 @@ +/** @odoo-module **/ + +import { WebsiteTranslator } from '@website/components/translator/translator'; +import { patch } from "@web/core/utils/patch"; + +patch(WebsiteTranslator.prototype, { + /** + * @override + */ + _beforeEditorActive() { + super._beforeEditorActive(...arguments); + $(this.websiteService.pageDocument).find('[data-translate-error-tooltip]').tooltip({ + container: this.websiteService.pageDocument.body, + trigger: 'click', + delay: {'show': 0, 'hide': 0}, + title: function () { + return $(this).data('translate-error-tooltip'); + }, + }); + } +});