From 43ea1ce5219958e30a1d84799371753cdfd09abd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guntars=20Pu=C5=BEulis?= Date: Thu, 23 Nov 2023 11:05:46 +0200 Subject: [PATCH] Merged PR 11501: Fix retranslation same segment multiple times. Fix retranslation same segment multiple times. Related work items: #66775 (cherry picked from commit 3be5106939fda36ff1cf6e4d7045a1e2e4ec0f1a) --- src/js/lib/DOMTranslation.ts | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/js/lib/DOMTranslation.ts b/src/js/lib/DOMTranslation.ts index 27f269c..961c389 100644 --- a/src/js/lib/DOMTranslation.ts +++ b/src/js/lib/DOMTranslation.ts @@ -1051,6 +1051,19 @@ class DOMTranslation { ) } + private addUserElementToCollection (collection: Set, element) { + if ( + element.nodeType === Node.ELEMENT_NODE && ( + element.nodeName === TILDE_MT_RAW_TEXT_NODE_TAG || + element.nodeName === TILDE_MT_TEXT_MARKER_START_TAG || + element.nodeName === TILDE_MT_TEXT_MARKER_END_TAG + ) + ) { + return + } + collection.add(element) + } + /** * * @param translatableParentElements @@ -1108,21 +1121,22 @@ class DOMTranslation { if (element.nodeName === 'SELECT') { forceVisibility = true } - translatableElements.add(element) + + this.addUserElementToCollection(translatableElements, element) } } else if (mode === TranslationElementMode.METADATA_ELEMENTS) { const hasSeoAttributes = this.getTranslatableAttributes(element) .some(item => item.type === TranslatableItemType.ATTRIBUTE_SEO) if (hasSeoAttributes) { - translatableElements.add(element) + this.addUserElementToCollection(translatableElements, element) } } else if (mode === TranslationElementMode.URLS) { if (element.nodeType === Node.ELEMENT_NODE) { const htmlElement = (element as HTMLElement) if (htmlElement.parentNode.nodeName !== 'HEAD' && htmlElement.hasAttribute('HREF')) { - translatableElements.add(element) + this.addUserElementToCollection(translatableElements, element) } } } @@ -1169,8 +1183,9 @@ class DOMTranslation { const metadataChildAllowed = mode === TranslationElementMode.METADATA_ELEMENTS && TranslationElementCandidates.get(element.parentElement.nodeName)?.type === TranslatableItemType.ELEMENT_SEO if (visibleChildAllowed || metadataChildAllowed || forceVisibility) { - translatableParentElements.add(currentParent) - translatableElements.add(element) + this.addUserElementToCollection(translatableParentElements, currentParent) + + this.addUserElementToCollection(translatableElements, element) } } }