forked from nunocoracao/blowfish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
findMissingTranslations.js
75 lines (61 loc) · 2.1 KB
/
findMissingTranslations.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
const fs = require('fs');
const configDir = "./exampleSite/config/_default";
const contentDir = "./exampleSite/content";
const defaultLang = "en";
var targetLangs = []
function readConfigs() {
const files = fs.readdirSync(configDir);
files.forEach(file => {
//console.log(file)
if(file.indexOf("languages.") > -1) {
var lang = file.split(".")[1];
//console.log(lang)
if(lang != defaultLang) {
targetLangs.push(lang);
}
}
});
}
async function processFile(filePath, file) {
if (filePath.indexOf("index.md") > -1) {
//console.log("processing", filePath)
for(var i in targetLangs) {
const targetLang = targetLangs[i];
var targetFilePath = filePath.replace(".md", "." + targetLang + ".md");
//var targetFileName = file.replace(".md", "." + targetLang + ".md");
if(fs.existsSync(targetFilePath)) {
//console.log("file already exists", targetFilePath);
const data = fs.readFileSync(filePath, 'utf8');
const data2 = fs.readFileSync(targetFilePath, 'utf8');
if(data != data2) {
//console.log("file contents are different", targetFilePath);
}else{
//console.log("file contents are the same", targetFilePath);
console.log(targetFilePath);
//process.exit(1);
}
}else{
//console.log("file does not exist", targetFilePath);
}
}
} else
return
}
async function processFolder(folderPath) {
const files = fs.readdirSync(folderPath);
for (var i in files) {
const file = files[i];
const filePath = `${folderPath}/${file}`;
const isDir = fs.lstatSync(filePath).isDirectory();
if (isDir) {
await processFolder(filePath);
} else {
await processFile(filePath, file);
}
}
}
async function createLinks() {
processFolder(contentDir);
}
readConfigs();
createLinks();