From ad8e80c90a7ce9dcf1e86ad55cd94d34a5bb1348 Mon Sep 17 00:00:00 2001
From: xO-Tx
Date: Mon, 22 May 2023 15:55:58 +0000
Subject: [PATCH] [FIX] website: correctly mark translatable attributes
Steps to reproduce:
- Go to a website page > Add a 'Form' block > Set an input "Placeholder"
value.
- Go to the page (in 'edit_translations' mode) > The translation of the
input "Placeholder" attribute doesn't mark the input as translated and
even after saving the translation, the input is still marked as
"to_translate".
The goal of this commit is to fix this issue by extending the same
behaviour on the translated `` options (using `.oe_translated`
class) and setting the right translation state on the input from the
linked attribute translation ``.
task-3323245
closes odoo/odoo#122011
X-original-commit: 946de52ea80e0cf5f1284cea2134c22ffda3aa5f
Signed-off-by: Benoit Socias (bso)
Signed-off-by: Outagant Mehdi (mou)
---
.../src/components/translator/translator.js | 10 +++++++++-
.../website/static/src/scss/website.wysiwyg.scss | 2 +-
addons/website/static/tests/tours/rte.js | 15 +++++++++++++--
3 files changed, 23 insertions(+), 4 deletions(-)
diff --git a/addons/website/static/src/components/translator/translator.js b/addons/website/static/src/components/translator/translator.js
index 20b6144d45e..10cb1a1b173 100644
--- a/addons/website/static/src/components/translator/translator.js
+++ b/addons/website/static/src/components/translator/translator.js
@@ -36,6 +36,7 @@ export class AttributeTranslateDialog extends Component {
$originalNode.val(value).trigger('translate');
}
$node.trigger('change');
+ $originalNode[0].classList.add('oe_translated');
});
$group.append($label).append($input);
}
@@ -58,7 +59,7 @@ export class SelectTranslateDialog extends Component {
const value = this.inputEl.el.value;
this.optionEl.textContent = value;
this.optionEl.classList.toggle(
- 'o_option_translated',
+ 'oe_translated',
value !== this.optionEl.dataset.initialTranslationValue
);
}
@@ -320,6 +321,13 @@ export class WebsiteTranslator extends WebsiteEditorComponent {
Object.values(translation).forEach((node) => {
var trans = self.getTranslationObject(node);
trans.value = (trans.value ? trans.value : $node.html()).replace(/[ \t\n\r]+/, ' ');
+ trans.state = node.dataset.oeTranslationState;
+ // If a node has an already translated attribute, we don't
+ // need to update its state, since it can be set again as
+ // "to_translate" by other attributes...
+ if ($node[0].dataset.oeTranslationState === 'translated') {
+ return;
+ }
$node.attr('data-oe-translation-state', (trans.state || 'to_translate'));
});
});
diff --git a/addons/website/static/src/scss/website.wysiwyg.scss b/addons/website/static/src/scss/website.wysiwyg.scss
index 1c7fa607db1..ec2c4f133ab 100644
--- a/addons/website/static/src/scss/website.wysiwyg.scss
+++ b/addons/website/static/src/scss/website.wysiwyg.scss
@@ -32,7 +32,7 @@ html[lang] > body.editor_enable [data-oe-translation-state] {
}
}
- &.o_dirty, .o_option_translated {
+ &.o_dirty, &.oe_translated, .oe_translated {
background: rgba($o-we-translated-content-color, 0.25) !important;
}
}
diff --git a/addons/website/static/tests/tours/rte.js b/addons/website/static/tests/tours/rte.js
index ee172906e4a..a1e594ffdc0 100644
--- a/addons/website/static/tests/tours/rte.js
+++ b/addons/website/static/tests/tours/rte.js
@@ -84,7 +84,7 @@ wTourUtils.registerWebsitePreviewTour('rte_translator', {
run: function () {
$('iframe:not(.o_ignore_in_tour)').contents().find("#wrap p:first").replaceWith('
Write one or two paragraphs describing your product or\
services. To be successful your content needs to be\
- useful to your readers.