Skip to content

Commit

Permalink
Merge pull request #16 from tilde-nlp/fix/retranslation
Browse files Browse the repository at this point in the history
Merged PR 11501: Fix retranslation same segment multiple times.
  • Loading branch information
gunpuz authored Nov 23, 2023
2 parents f1b61e2 + 43ea1ce commit 9972dbc
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 9972dbc

Please sign in to comment.