forked from terraforming-mars/terraforming-mars
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_locales.js
37 lines (28 loc) · 1.18 KB
/
make_locales.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
const fs = require("fs");
const path = require("path");
function getAllTranslations() {
let pathToTranslationsDir = path.resolve("src/locales")
let translations = {};
let translationDir = "";
let dirs = fs.readdirSync(pathToTranslationsDir);
for (let idx in dirs) {
let lang = dirs[idx];
let localeDir = path.join(pathToTranslationsDir, lang);
if (lang.length === 2 && fs.statSync(localeDir).isDirectory()) {
translations[lang] = {};
translationDir = path.resolve(path.join(pathToTranslationsDir, lang));
let files = fs.readdirSync(translationDir);
for (let idx in files) {
let file = files[idx];
if ( file === undefined || ! file.endsWith(".json")) continue;
let dataJson = JSON.parse(fs.readFileSync(path.join(translationDir, file),"utf8"));
for (let k in dataJson) {
translations[lang][k] = dataJson[k];
}
}
}
}
return translations;
}
let translationsJSON = JSON.stringify(getAllTranslations());
fs.writeFileSync("assets/translations.json", translationsJSON);