From 1165028aac344c37968a1989ec596ebda99fec2c Mon Sep 17 00:00:00 2001 From: qsm-odoo Date: Thu, 8 Feb 2024 14:36:57 +0100 Subject: [PATCH] [FIX] web_editor: stop auto-capitalize of editor UI labels (translation) Commit [1] added a rule whose intention was to unify the way our editor labels look: capitalized. However, this is not working as intended for translations as some languages have different rules for capitalization. In the future, we will rely solely on the labels being written with the intended capitalization in the first place (which is currently not the case for dozens of English labels). As a fix, we keep the auto CSS rule for English languages only. Hopefully, the amount of translations made by translators being better than their auto-capitalized versions is greater than non-capitalized English labels translated by mistake without the auto-capitalization. Note: this is the way python fields work too, they are not displayed auto-capitalized in the webclient, although we want them to be. [1]: https://github.com/odoo/odoo/commit/5db73c12d3ed14239dc81f60eec6c21d0f65af26 closes odoo/odoo#153732 X-original-commit: 453b1e86840d81ffeff4d182b161b0ea50a38486 Signed-off-by: Romain Derie (rde) Signed-off-by: Quentin Smetz (qsm) --- .../web_editor/static/src/js/editor/snippets.editor.js | 8 ++++++++ addons/web_editor/static/src/scss/wysiwyg_snippets.scss | 9 ++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/addons/web_editor/static/src/js/editor/snippets.editor.js b/addons/web_editor/static/src/js/editor/snippets.editor.js index 06a62034792..2d60f2bbf7e 100644 --- a/addons/web_editor/static/src/js/editor/snippets.editor.js +++ b/addons/web_editor/static/src/js/editor/snippets.editor.js @@ -4,6 +4,7 @@ import { Mutex } from "@web/core/utils/concurrency"; import { clamp } from "@web/core/utils/numbers"; import { ConfirmationDialog } from "@web/core/confirmation_dialog/confirmation_dialog"; import dom from "@web/legacy/js/core/dom"; +import { session } from "@web/session"; import Widget from "@web/legacy/js/core/widget"; import { useDragAndDrop } from "@web_editor/js/editor/drag_and_drop"; import options from "@web_editor/js/editor/snippets.options"; @@ -1867,6 +1868,13 @@ var SnippetsMenu = Widget.extend({ // own window and not on the top window lest jquery behave unexpectedly. this.$el = this.window.$(this.$el); this.$el.data('snippetMenu', this); + + // TODO somehow this attribute is not on the HTML element of the backend + // ... it probably should be. + const context = this.options.context || session.user_context || {}; + const userLang = context.user_lang || context.lang || 'en_US'; + this.el.setAttribute('lang', userLang.replace('_', '-')); + // We need to activate the touch events to be able to drag and drop // snippets on devices with a touch screen. this.__onTouchEvent = this._onTouchEvent.bind(this); diff --git a/addons/web_editor/static/src/scss/wysiwyg_snippets.scss b/addons/web_editor/static/src/scss/wysiwyg_snippets.scss index 2064b183263..34cf0a02fcb 100644 --- a/addons/web_editor/static/src/scss/wysiwyg_snippets.scss +++ b/addons/web_editor/static/src/scss/wysiwyg_snippets.scss @@ -855,10 +855,17 @@ we-title { display: block; - text-transform: capitalize; text-align: left; } + // TODO in master, remove the text-transform rule entirely and rely on + // developers writing their label with the intended "design". The + // "where" change here was added as a way to minimize the impact of this + // fix in stable. That CSS style was breaking translations. + we-title:where(:lang(en)) { + text-transform: capitalize; + } + we-customizeblock-options { position: relative; display: block;