mirror of
https://github.com/SchildiChat/schildichat-desktop.git
synced 2025-06-11 05:00:47 +02:00
Add stuff for automatic i18n adjustment
This commit is contained in:
3
i18n-helper/.gitignore
vendored
Normal file
3
i18n-helper/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
yarn.lock
|
||||
yarn-error.log
|
||||
node_modules/
|
52
i18n-helper/index.js
Normal file
52
i18n-helper/index.js
Normal 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
8
i18n-helper/package.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"name": "i18n-helper",
|
||||
"version": "0.0.1",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"globby": "^11.0.3"
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user