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:
parent
367bfd2962
commit
022fc8c374
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue