Skip to content

Commit

Permalink
Merged PR 11501: Fix retranslation same segment multiple times.
Browse files Browse the repository at this point in the history
Fix retranslation same segment multiple times.

Related work items: #66775

(cherry picked from commit 3be5106939fda36ff1cf6e4d7045a1e2e4ec0f1a)
  • Loading branch information
gunpuz committed Nov 23, 2023
1 parent f1b61e2 commit 43ea1ce
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions src/js/lib/DOMTranslation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1051,6 +1051,19 @@ class DOMTranslation {
)
}

private addUserElementToCollection (collection: Set<HTMLElement>, 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
Expand Down Expand Up @@ -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)
}
}
}
Expand Down Expand Up @@ -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)
}
}
}
Expand Down

0 comments on commit 43ea1ce

Please sign in to comment.