forked from psemu/soe-locale
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocale.js
56 lines (49 loc) · 1.72 KB
/
locale.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
50
51
52
53
54
55
#!/usr/bin/env node
var fs = require("fs"),
locale = require("./soe-locale.js");
var mode = process.argv[2];
switch (mode) {
case "parse":
var inPathData = process.argv[3],
inPathIndex = process.argv[4],
outPath = process.argv[5];
if (!fs.existsSync(inPathData)) {
throw "inPathData does not exist: " + inPathData;
}
if (!fs.existsSync(inPathIndex)) {
throw "inPathIndex does not exist: " + inPathIndex;
}
console.log("Reading index and string data...");
locale.parse(inPathData, inPathIndex, function(err, strings) {
if (!err) {
console.log("Writing locale data to file: " + outPath);
fs.writeFile(outPath, JSON.stringify(strings, null, 4));
console.log("Done!");
} else {
throw err;
}
});
break;
case "write":
var inPath = process.argv[3],
outPathData = process.argv[4],
outPathIndex = process.argv[5];
if (!fs.existsSync(inPath)) {
throw "inPath does not exist: " + inPath;
}
console.log("Reading string data...");
var stringData = fs.readFileSync(inPath);
console.log("Parsing JSON...");
var strings = JSON.parse(stringData);
console.log("Writing string and index data to " + outPathData + " and " + outPathIndex);
locale.write(strings, outPathData, outPathIndex, function(err) {
if (!err) {
console.log("Done!");
} else {
throw err;
}
});
break;
default:
console.log("Usage: node locale.js <mode> ...");
}