Sort translations by file name

This keeps the strings close together and roughly in the same area as the others, and makes it easier to maintain the translation file.
This commit is contained in:
Travis Ralston 2018-12-05 11:52:10 -07:00
parent c06d42d560
commit a2b825ba92
2 changed files with 25 additions and 13 deletions

View file

@ -222,10 +222,21 @@ const translatables = new Set();
const walkOpts = {
listeners: {
names: function(root, nodeNamesArray) {
// Sort the names case insensitively and alphabetically to
// maintain some sense of order between the different strings.
nodeNamesArray.sort((a, b) => {
a = a.toLowerCase();
b = b.toLowerCase();
if (a > b) return 1;
if (a < b) return -1;
return 0;
});
},
file: function(root, fileStats, next) {
const fullPath = path.join(root, fileStats.name);
let ltrs;
let trs;
if (fileStats.name.endsWith('.js')) {
trs = getTranslationsJs(fullPath);
} else if (fileStats.name.endsWith('.html')) {
@ -235,7 +246,8 @@ const walkOpts = {
}
console.log(`${fullPath} (${trs.size} strings)`);
for (const tr of trs.values()) {
translatables.add(tr);
// Convert DOS line endings to unix
translatables.add(tr.replace(/\r\n/g, "\n"));
}
},
}