From 3e89eeb459b9e4ed527b9b64f9339b27118009dd Mon Sep 17 00:00:00 2001 From: Dannon Baker Date: Tue, 16 Apr 2024 16:24:22 -0400 Subject: [PATCH] Preserve surrounding whitespace when localizing complex nodes --- client/src/components/plugins/localization.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/client/src/components/plugins/localization.js b/client/src/components/plugins/localization.js index cf6c196778b2..896cb6756fd2 100644 --- a/client/src/components/plugins/localization.js +++ b/client/src/components/plugins/localization.js @@ -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; }); }, };