forked from navcoin/navcoin-org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap-translation.js
60 lines (47 loc) · 1.77 KB
/
bootstrap-translation.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
var fs = require('fs');
if (process.argv.length <= 2) {
console.log('Usage: ' + __filename + ' languagecode');
process.exit(-1);
}
const languageCode = process.argv[2];
const path = './content/';
fs.readdir(path, function (err, items) {
let dirs = items.filter((item) => {
const stats = fs.statSync(`${path}/${item}`)
if (stats.isDirectory()) {
return true
}
return false
})
for (var i = 0; i < dirs.length; i++) {
duplicateEnglishMarkdown(`${path}${dirs[i]}/`, languageCode);
}
duplicateEnglishMarkdown(path, languageCode);
console.warn(`\n\n Please ensure that you update the config.toml file so that it has the relevevant menu entries for your translation \n\n`);
});
function duplicateEnglishMarkdown(dirPath, languageCode) {
fs.readdir(dirPath, function (err, items) {
let englishFiles = items.filter((item) => {
if (item.includes('.en.md') || item.includes('.en.html'))
return true
return false
})
for (var i = 0; i < englishFiles.length; i++) {
const splitFile = englishFiles[i].split('.');
const fileName = splitFile[0];
const fileExt = splitFile[splitFile.length - 1];
const translationFilename = `${fileName}.${languageCode}.${fileExt}`;
try {
// Look for the file, if it exists we log. If we can't find it, we will error, and then generate the file.
fs.statSync(dirPath + translationFilename)
console.error(`**** ${dirPath + translationFilename} exists ****`)
return
} catch (e) {
fs.copyFile(`${dirPath + englishFiles[i]}`, `${dirPath + translationFilename}`, (err) => {
if (err) throw err;
console.log(`${dirPath}${fileName}.en.${fileExt} was copied as ${translationFilename}`);
})
}
}
});
}