Skip to content

Commit

Permalink
Preserve surrounding whitespace when localizing complex nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
dannon committed Apr 16, 2024
1 parent eeca0f1 commit 3e89eeb
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion client/src/components/plugins/localization.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
},
};
Expand Down

0 comments on commit 3e89eeb

Please sign in to comment.