-
Notifications
You must be signed in to change notification settings - Fork 1
/
faq.js
99 lines (86 loc) · 2.12 KB
/
faq.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
var fs = require("fs");
var fsextra = require('fs-extra');
var languageList = [
"Assamese",
"Bengali",
"English",
"Gujarati",
"Hindi",
"Kannada",
"Marathi",
"Oriya",
"Punjabi",
"Tamil",
"Telugu",
"Urdu"
];
var languageCodeList = [
"as",
"bn",
"en",
"gu",
"hi",
"kn",
"mr",
"or",
"pa",
"ta",
"te",
"ur"
];
formatFaqTranslations();
async function formatFaqTranslations() {
createSubFolders('.', 'res');
for (let i = 0; i < languageList.length; i++) {
const data = await readFile(languageList[i]);
const response = {
"faqs": [],
"constants": {}
};
if (data['constants']) {
response.constants = data['constants'];
}
//console.log(Object.keys(data));
var j = 1;
while (data['FAQ_' + j] && data['ANS_' + j]) {
console.log(j, data['FAQ_' + j]);
response.faqs.push({ "topic": data['FAQ_' + j], "description": data['ANS_' + j] });
j++;
}
await writeFile('res', 'faq-' + languageCodeList[i], JSON.stringify(response));
}
}
async function readFile(fileName) {
var data = JSON.parse(fs.readFileSync('./' + fileName + '.json', 'utf8'));
return new Promise((resolve, reject) => {
resolve(data);
});
}
async function writeFile(dirName, fileName, response) {
return new Promise((resolve, reject) => {
var name = dirName + '/' + fileName + '.json';
fs.writeFile(name, response, (err) => {
if (err) {
reject(err);
} else {
console.log("File " + name + " saved")
resolve();
}
});
});
}
function createSubFolders(rootDir, dirName) {
var dir = rootDir + '/' + dirName;
return new Promise((resolve, reject) => {
try {
if (!fs.existsSync(dir)) {
fsextra.ensureDirSync(dir);
resolve(dir);
} else {
resolve(dir)
}
} catch (err) {
reject(err);
}
});
}