2021-09-15 19:52:39 +01:00
|
|
|
// Need to use ES6 to read language files
|
2021-09-01 10:08:27 +01:00
|
|
|
|
|
|
|
import fs from "fs";
|
|
|
|
import path from "path";
|
|
|
|
import util from "util";
|
|
|
|
|
|
|
|
// https://stackoverflow.com/questions/13786160/copy-folder-recursively-in-node-js
|
|
|
|
/**
|
|
|
|
* Look ma, it's cp -R.
|
|
|
|
* @param {string} src The path to the thing to copy.
|
|
|
|
* @param {string} dest The path to the new copy.
|
|
|
|
*/
|
|
|
|
const copyRecursiveSync = function (src, dest) {
|
|
|
|
let exists = fs.existsSync(src);
|
|
|
|
let stats = exists && fs.statSync(src);
|
|
|
|
let isDirectory = exists && stats.isDirectory();
|
2021-09-15 19:52:39 +01:00
|
|
|
|
2021-09-01 10:08:27 +01:00
|
|
|
if (isDirectory) {
|
|
|
|
fs.mkdirSync(dest);
|
|
|
|
fs.readdirSync(src).forEach(function (childItemName) {
|
|
|
|
copyRecursiveSync(path.join(src, childItemName),
|
|
|
|
path.join(dest, childItemName));
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
fs.copyFileSync(src, dest);
|
|
|
|
}
|
|
|
|
};
|
2021-09-15 19:52:39 +01:00
|
|
|
|
2021-09-15 19:57:36 +01:00
|
|
|
console.log("Arguments:", process.argv)
|
2021-09-15 19:52:39 +01:00
|
|
|
const baseLangCode = process.argv[2] || "en";
|
2021-09-01 10:08:27 +01:00
|
|
|
console.log("Base Lang: " + baseLangCode);
|
|
|
|
fs.rmdirSync("./languages", { recursive: true });
|
|
|
|
copyRecursiveSync("../../src/languages", "./languages");
|
|
|
|
|
|
|
|
const en = (await import("./languages/en.js")).default;
|
|
|
|
const baseLang = (await import(`./languages/${baseLangCode}.js`)).default;
|
|
|
|
const files = fs.readdirSync("./languages");
|
2021-09-15 19:57:36 +01:00
|
|
|
console.log("Files:", files);
|
2021-09-15 19:52:39 +01:00
|
|
|
|
2021-09-01 10:08:27 +01:00
|
|
|
for (const file of files) {
|
2021-09-15 19:52:39 +01:00
|
|
|
if (!file.endsWith(".js")) {
|
|
|
|
console.log("Skipping " + file)
|
|
|
|
continue;
|
|
|
|
}
|
2021-09-01 10:08:27 +01:00
|
|
|
|
2021-09-15 19:52:39 +01:00
|
|
|
console.log("Processing " + file);
|
|
|
|
const lang = await import("./languages/" + file);
|
2021-09-01 10:08:27 +01:00
|
|
|
|
2021-09-15 19:52:39 +01:00
|
|
|
let obj;
|
2021-09-01 10:08:27 +01:00
|
|
|
|
2021-09-15 19:52:39 +01:00
|
|
|
if (lang.default) {
|
|
|
|
obj = lang.default;
|
|
|
|
} else {
|
|
|
|
console.log("Empty file");
|
|
|
|
obj = {
|
|
|
|
languageName: "<Your Language name in your language (not in English)>"
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// En first
|
|
|
|
for (const key in en) {
|
|
|
|
if (! obj[key]) {
|
|
|
|
obj[key] = en[key];
|
2021-09-01 10:08:27 +01:00
|
|
|
}
|
2021-09-15 19:52:39 +01:00
|
|
|
}
|
2021-09-01 10:08:27 +01:00
|
|
|
|
2021-09-15 19:52:39 +01:00
|
|
|
if (baseLang !== en) {
|
2021-09-01 10:08:27 +01:00
|
|
|
// Base second
|
|
|
|
for (const key in baseLang) {
|
|
|
|
if (! obj[key]) {
|
|
|
|
obj[key] = key;
|
|
|
|
}
|
|
|
|
}
|
2021-09-15 19:52:39 +01:00
|
|
|
}
|
2021-09-01 10:08:27 +01:00
|
|
|
|
2021-09-15 19:52:39 +01:00
|
|
|
const code = "export default " + util.inspect(obj, {
|
|
|
|
depth: null,
|
|
|
|
});
|
2021-09-01 10:08:27 +01:00
|
|
|
|
2021-09-15 19:52:39 +01:00
|
|
|
fs.writeFileSync(`../../src/languages/${file}`, code);
|
2021-09-01 10:08:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
fs.rmdirSync("./languages", { recursive: true });
|
2021-09-15 19:52:39 +01:00
|
|
|
console.log("Done. Fixing formatting by ESLint...");
|