diff options
author | Pierre Ossman <ossman@cendio.se> | 2022-12-27 15:25:06 +0100 |
---|---|---|
committer | Pierre Ossman <ossman@cendio.se> | 2022-12-27 15:39:11 +0100 |
commit | 022fc8c3747afd9d5afcba47f66f7b73a9c1a39f (patch) | |
tree | fc19ba36fde6265695f5de6ceefb5cf734c52276 | |
parent | 367bfd296228d94b00c18e5b37cc03e34822eb64 (diff) | |
download | novnc-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.
-rw-r--r-- | app/localization.js | 11 | ||||
-rwxr-xr-x | po/xgettext-html | 6 |
2 files changed, 14 insertions, 3 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; } diff --git a/po/xgettext-html b/po/xgettext-html index bb30d3b..ae53461 100755 --- a/po/xgettext-html +++ b/po/xgettext-html @@ -17,6 +17,10 @@ const opt = getopt.create([ const strings = {}; function addString(str, location) { + // We assume surrounding whitespace, and whitespace around line + // breaks, is just for source formatting + str = str.split("\n").map(s => s.trim()).join(" ").trim(); + if (str.length == 0) { return; } @@ -78,7 +82,7 @@ function process(elem, locator, enabled) { if (node.nodeType === node.ELEMENT_NODE) { process(node, locator, enabled); } else if (node.nodeType === node.TEXT_NODE && enabled) { - addString(node.data.trim(), locator(node)); + addString(node.data, locator(node)); } } } |