summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorPierre Ossman <ossman@cendio.se>2022-12-27 15:25:06 +0100
committerPierre Ossman <ossman@cendio.se>2022-12-27 15:39:11 +0100
commit022fc8c3747afd9d5afcba47f66f7b73a9c1a39f (patch)
treefc19ba36fde6265695f5de6ceefb5cf734c52276 /app
parent367bfd296228d94b00c18e5b37cc03e34822eb64 (diff)
downloadnovnc-022fc8c3747afd9d5afcba47f66f7b73a9c1a39f.tar.gz
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.
Diffstat (limited to 'app')
-rw-r--r--app/localization.js11
1 files changed, 9 insertions, 2 deletions
diff --git a/app/localization.js b/app/localization.js
index 100901c..84341da 100644
--- a/app/localization.js
+++ b/app/localization.js
@@ -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;
}