forked from shd101wyy/markdown-preview-enhanced
-
Notifications
You must be signed in to change notification settings - Fork 0
/
simplified_chinese_2_traditional_chinese_script.js
60 lines (47 loc) · 1.46 KB
/
simplified_chinese_2_traditional_chinese_script.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
56
57
58
59
60
const chineseConv = require("chinese-conv"),
fs = require("fs"),
path = require("path");
/*
This script is used to convert the simplified Chinese *.md files inside /docs/zh-cn folder to Tranditional Chinese for /docs/zh-tw
To run this script:
node simplified_chinese_2_traditional_chinese_script.js
*/
const ignoreFiles = ["installation.md"];
zhTWDir = path.resolve(__dirname, "./docs/zh-tw");
zhCNDir = path.resolve(__dirname, "./docs/zh-cn");
/*
// delete all markdown files inside /docs/zh-tw
fs.readdir(zhTWDir, (error, items)=> {
if (error)
return console.log(error)
items.forEach((fileName)=> {
for (let i = 0; i < ignoreFiles.length; i++) {
if (ignoreFiles[i] === fileName)
return
}
fs.unlink(path.resolve(zhTWDir, fileName))
})
})
*/
// translate
fs.readdir(zhCNDir, (error, items) => {
if (error) return console.log(error);
items.forEach((fileName) => {
for (let i = 0; i < ignoreFiles.length; i++) {
if (ignoreFiles[i] === fileName) return;
}
const filePath = path.resolve(zhCNDir, fileName);
fs.readFile(filePath, { encoding: "utf-8" }, (error, data) => {
if (error) return console.log(error);
let text = chineseConv.tify(data).replace(/\]\(\s*zh\-cn\//g, "](zh-tw/");
fs.writeFile(
path.resolve(zhTWDir, fileName),
text,
{ encoding: "utf-8" },
(error) => {
if (error) return console.log(error);
},
);
});
});
});