Add stuff for automatic i18n adjustment

This commit is contained in:
su-ex
2021-05-29 03:29:10 +02:00
parent ac9cf5e2d6
commit c18cc22db7
11 changed files with 252 additions and 0 deletions

3
i18n-helper/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
yarn.lock
yarn-error.log
node_modules/

52
i18n-helper/index.js Normal file
View File

@ -0,0 +1,52 @@
const fs = require('fs');
const path = require('path');
const globby = require('globby');
function readStrings(p) {
return JSON.parse(fs.readFileSync(p).toString());
}
function writeStrings(p, strings) {
fs.writeFileSync(p, JSON.stringify(strings, null, 4) + "\n");
}
(async () => {
console.log(process.argv.length);
console.log(process.argv[0]);
console.log(process.argv[1]);
console.log(process.argv[2]);
console.log(process.argv[3]);
if (process.argv.length < 3) {
console.log("No path with the original strings given!");
process.exit(-1);
}
originalPath = process.argv[2];
overlayPath = null;
if (process.argv.length > 3) {
overlayPath = process.argv[3];
} else {
console.log("Continue without overlays ...")
}
const paths = await globby(path.join(originalPath, "*.json"));
paths.forEach(p => {
let strings = readStrings(p);
for (const key of Object.keys(strings)) {
strings[key] = strings[key].replace(/Element/g, "SchildiChat").replace(/element\.io/g, "schildi.chat");
}
if (overlayPath) {
op = path.join(overlayPath, path.basename(p));
if (fs.existsSync(op)) {
overlayStrings = readStrings(op);
Object.assign(strings, overlayStrings);
}
}
writeStrings(p, strings);
});
})();

8
i18n-helper/package.json Normal file
View File

@ -0,0 +1,8 @@
{
"name": "i18n-helper",
"version": "0.0.1",
"main": "index.js",
"dependencies": {
"globby": "^11.0.3"
}
}