Improve whitespace handling in translations

The HTML source will include line breaks and indentation that is only
for source formatting, and will not be displayed.
This commit is contained in:
Pierre Ossman
2022-12-27 15:25:06 +01:00
parent 367bfd2962
commit 022fc8c374
2 changed files with 14 additions and 3 deletions
+9 -2
View File
@@ -103,13 +103,20 @@ export class Localizer {
return items.indexOf(searchElement) !== -1;
}
function translateString(str) {
// We assume surrounding whitespace, and whitespace around line
// breaks is just for source formatting
str = str.split("\n").map(s => s.trim()).join(" ").trim();
return self.get(str);
}
function translateAttribute(elem, attr) {
const str = self.get(elem.getAttribute(attr));
const str = translateString(elem.getAttribute(attr));
elem.setAttribute(attr, str);
}
function translateTextNode(node) {
const str = self.get(node.data.trim());
const str = translateString(node.data);
node.data = str;
}