Merge pull request #18005 from dannon/fix-localization-spacing

[24.0] Preserve surrounding whitespace when localizing complex nodes
This commit is contained in:
David López
2024-04-17 10:27:44 +02:00
committed by GitHub
@@ -12,11 +12,14 @@ function localizeDirective(l) {
// TODO consider using a different hook if we need dynamic updates in content translation
bind(el, binding, vnode) {
el.childNodes.forEach((node) => {
// trim for lookup, but put back whitespace after
const leadingSpace = node.textContent.match(/^\s*/)[0];
const trailingSpace = node.textContent.match(/\s*$/)[0];
const standardizedContent = node.textContent
.replace(newlineMatch, " ")
.replace(doublespaces, " ")
.trim();
node.textContent = l(standardizedContent);
node.textContent = leadingSpace + l(standardizedContent) + trailingSpace;
});
},
};