commit
3b0191210b
@ -0,0 +1,3 @@
|
|||||||
|
package-lock.json
|
||||||
|
test.js
|
||||||
|
languages/
|
@ -0,0 +1,77 @@
|
|||||||
|
// Need to use es6 to read language files
|
||||||
|
|
||||||
|
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();
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
console.log(process.argv)
|
||||||
|
const baseLangCode = process.argv[2] || "zh-HK";
|
||||||
|
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");
|
||||||
|
console.log(files);
|
||||||
|
for (const file of files) {
|
||||||
|
if (file.endsWith(".js")) {
|
||||||
|
console.log("Processing " + file);
|
||||||
|
const lang = await import("./languages/" + file);
|
||||||
|
|
||||||
|
let obj;
|
||||||
|
|
||||||
|
if (lang.default) {
|
||||||
|
console.log("is js module");
|
||||||
|
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];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Base second
|
||||||
|
for (const key in baseLang) {
|
||||||
|
if (! obj[key]) {
|
||||||
|
obj[key] = key;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const code = "export default " + util.inspect(obj, {
|
||||||
|
depth: null,
|
||||||
|
});
|
||||||
|
|
||||||
|
fs.writeFileSync(`../../src/languages/${file}`, code);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fs.rmdirSync("./languages", { recursive: true });
|
@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"name": "update-language-files",
|
||||||
|
"type": "module",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"author": "",
|
||||||
|
"license": "ISC"
|
||||||
|
}
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,10 @@
|
|||||||
|
# How to translate
|
||||||
|
|
||||||
|
1. Fork this repo.
|
||||||
|
2. Create a language file. (e.g. zh-TW.js) The filename must be ISO language code: http://www.lingoes.net/en/translator/langcode.htm
|
||||||
|
3. `npm run update-language-files --base-lang=de-DE`
|
||||||
|
6. Your language file should be filled in. You can translate now.
|
||||||
|
7. Make a pull request when you have done.
|
||||||
|
|
||||||
|
If you do not have programming skills, let me know in Issue section. I will assist you. 😏
|
||||||
|
|
Loading…
Reference in new issue