mirror of
https://github.com/koodo-reader/koodo-reader.git
synced 2026-04-18 05:51:39 -04:00
- Implemented a script to list locale folders and identify missing translation terms in English. - Added functionality to copy missing terms from Chinese translations to English. - Enhanced the script to fill in missing terms for other languages based on the updated English file. - Created a patch script for nan.h to comment out the inclusion of nan_scriptorigin.h for cross-platform compatibility.
76 lines
2.4 KiB
JavaScript
76 lines
2.4 KiB
JavaScript
//list the folders in ./assets/locales
|
|
const fs = require("fs");
|
|
const path = require("path");
|
|
const localesPath = path.join(__dirname, "../src/assets/locales");
|
|
const folders = fs.readdirSync(localesPath);
|
|
let resources = [];
|
|
for (let index = 0; index < folders.length; index++) {
|
|
const folder = folders[index];
|
|
resources.push(`../src/assets/locales/${folder}/translation.json`);
|
|
}
|
|
console.log(resources);
|
|
|
|
// find the missing terms in the english
|
|
const zhdataRaw = fs.readFileSync(
|
|
path.join(__dirname, "../src/assets/locales/zh-CN/translation.json"),
|
|
"utf-8"
|
|
);
|
|
const enDataRaw = fs.readFileSync(
|
|
path.join(__dirname, "../src/assets/locales/en/translation.json"),
|
|
"utf-8"
|
|
);
|
|
//find the missing terms in the target language
|
|
// Step1
|
|
const zhData = JSON.parse(zhdataRaw);
|
|
const enData = JSON.parse(enDataRaw);
|
|
let missingTerms = {};
|
|
for (let index = 0; index < Object.keys(zhData).length; index++) {
|
|
const term = Object.keys(zhData)[index];
|
|
if (Object.keys(enData).indexOf(term) === -1) {
|
|
console.log(zhData[term]);
|
|
missingTerms[term] = term;
|
|
}
|
|
}
|
|
console.log(JSON.stringify(missingTerms));
|
|
console.log(Object.keys(zhData).length, Object.keys(enData).length);
|
|
|
|
// Step2: copy the missing terms to the english file
|
|
const mergedObj = Object.assign({}, enData, missingTerms);
|
|
fs.writeFileSync(
|
|
path.join(__dirname, "../src/assets/locales/en/translation.json"),
|
|
JSON.stringify(mergedObj, null, 2)
|
|
);
|
|
|
|
// Step3:
|
|
// fill out the rest of the terms in the target language
|
|
const data = fs.readFileSync(
|
|
path.join(__dirname, "../src/assets/locales/en/translation.json"),
|
|
"utf-8"
|
|
);
|
|
const referData = JSON.parse(data);
|
|
for (let index = 0; index < resources.length; index++) {
|
|
try {
|
|
const resource = resources[index];
|
|
console.log(path.join(__dirname, resource));
|
|
const data = fs.readFileSync(path.join(__dirname, resource), "utf-8");
|
|
const targetData = JSON.parse(data);
|
|
let missingTerms = {};
|
|
for (let index = 0; index < Object.keys(referData).length; index++) {
|
|
const term = Object.keys(referData)[index];
|
|
if (Object.keys(targetData).indexOf(term) === -1) {
|
|
console.log(referData[term]);
|
|
missingTerms[term] = referData[term];
|
|
}
|
|
}
|
|
// console.log(missingTerms);
|
|
const mergedObj = Object.assign({}, targetData, missingTerms);
|
|
|
|
fs.writeFileSync(
|
|
path.join(__dirname, resource),
|
|
JSON.stringify(mergedObj, null, 2)
|
|
);
|
|
} catch (error) {
|
|
console.error("Error reading JSON file:", error);
|
|
}
|
|
}
|