-
Notifications
You must be signed in to change notification settings - Fork 3
/
addstrs.js
49 lines (42 loc) · 1.47 KB
/
addstrs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const fs = require("fs");
const YAML = require("yaml");
const folder = process.argv[2].trim();
let count = 0;
if (["en-us", "en_us"].some(f => f == folder.toLowerCase())) {
console.error("You can't import to English!")
} else if (!fs.existsSync(`./${folder}`) || !fs.statSync(`./${folder}`).isDirectory()) {
console.error(`"${folder}" doesn't exist or is not a directory.`);
} else {
manage(`./en-US`, fs.readdirSync(`./en-US`));
console.log(`Done! Processed ${count} file(s).`)
}
/**
* @param {string[]} directory
*/
function manage(currentdir, directory) {
let path = `${currentdir}`
for (let file of directory) {
const tdir = `${path}/${file}`.replace("en-US", folder);
if (fs.statSync(`${path}/${file}`).isDirectory()) {
if (!fs.existsSync(tdir))
fs.mkdirSync(tdir)
manage(`${path}/${file}`, fs.readdirSync(`${path}/${file}`))
} else {
let translated, original;
t: {
let raw = fs.readFileSync(`${path}/${file}`).toString();
original = YAML.parse(raw);
}
o: {
try {
let raw = fs.readFileSync(tdir).toString();
translated = YAML.parse(raw);
} catch (e) {
translated = original;
}
}
fs.writeFileSync(tdir, YAML.stringify({ ...original, ...translated }));
count++;
}
}
}