From c99cd92c14517863a431e9f88de224945c8f8556 Mon Sep 17 00:00:00 2001 From: xO-Tx Date: Tue, 2 May 2023 14:30:03 +0000 Subject: [PATCH] [FIX] website, tools: make select options translatable Steps to reproduce: - Go to a website page > Add a 'Form' block > Add a new 'Selection' field. - Go to the page (in 'edit_translations' mode) > The selection field options are not translatable. The goal of this commit is to make the select options translatable by adding an intermediate `.o_translation_select` element. This element will handle option's text translations from the linked `` options since it should not be +// possible to interact with the content of `.o_translation_select` elements. +export class SelectTranslateDialog extends Component { + setup() { + this.title = this.env._t("Translate Selection Option"); + this.inputEl = useRef('input'); + this.optionEl = this.props.node; + } + + onInputKeyup() { + const value = this.inputEl.el.value; + this.optionEl.textContent = value; + this.optionEl.classList.toggle( + 'o_option_translated', + value !== this.optionEl.dataset.initialTranslationValue + ); + } +} +SelectTranslateDialog.components = {WebsiteDialog}; +SelectTranslateDialog.template = xml` + + + +`; + export class TranslatorInfoDialog extends Component { setup() { this.strongOkButton = this.env._t("Ok, never show me this again"); @@ -187,6 +218,23 @@ export class WebsiteTranslator extends WebsiteEditorComponent { } }); + // Hack: we add a temporary element to handle option's text + // translations from the linked `s since we use `.o_translation_select` + // elements to handle translations. + + select { + display: none !important; + } + > div:not(:last-child) { + border-bottom: inherit; + } + } +} //------------------------------------------------------------------------------ // Website Animate diff --git a/addons/website/static/src/scss/website.wysiwyg.scss b/addons/website/static/src/scss/website.wysiwyg.scss index d64292ea0a8..1c7fa607db1 100644 --- a/addons/website/static/src/scss/website.wysiwyg.scss +++ b/addons/website/static/src/scss/website.wysiwyg.scss @@ -22,13 +22,17 @@ } html[lang] > body.editor_enable [data-oe-translation-state] { - background: rgba($o-we-content-to-translate-color, 0.5) !important; - - &[data-oe-translation-state="translated"] { - background: rgba($o-we-translated-content-color, 0.5) !important; + &, .o_translation_select_option { + background: rgba($o-we-content-to-translate-color, 0.5) !important; } - &.o_dirty { + &[data-oe-translation-state="translated"] { + &, .o_translation_select_option { + background: rgba($o-we-translated-content-color, 0.5) !important; + } + } + + &.o_dirty, .o_option_translated { background: rgba($o-we-translated-content-color, 0.25) !important; } } diff --git a/odoo/tools/translate.py b/odoo/tools/translate.py index dbc1f9b0208..b88854c9ac5 100644 --- a/odoo/tools/translate.py +++ b/odoo/tools/translate.py @@ -147,7 +147,7 @@ TRANSLATED_ELEMENTS = { 'abbr', 'b', 'bdi', 'bdo', 'br', 'cite', 'code', 'data', 'del', 'dfn', 'em', 'font', 'i', 'ins', 'kbd', 'keygen', 'mark', 'math', 'meter', 'output', 'progress', 'q', 'ruby', 's', 'samp', 'small', 'span', 'strong', 'sub', - 'sup', 'time', 'u', 'var', 'wbr', 'text', + 'sup', 'time', 'u', 'var', 'wbr', 'text', 'select', 'option', } # Which attributes must be translated. This is a dict, where the value indicates