mirror of
https://github.com/kmvan/x-prober.git
synced 2026-08-13 01:39:30 +08:00
51 lines
1.4 KiB
JavaScript
51 lines
1.4 KiB
JavaScript
/**
|
|
* @version 1.0.1
|
|
*/
|
|
|
|
import { writeFileSync } from "node:fs";
|
|
import { glob } from "node:fs/promises";
|
|
import path, { basename, dirname } from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
import DeepSort from "deep-sort-object";
|
|
import { PoParser } from "./po-parser.mjs";
|
|
import { PotBuilder } from "./pot-builder.mjs";
|
|
|
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
class LangBuilder {
|
|
data = {};
|
|
async setData() {
|
|
new PotBuilder({
|
|
potPath: path.resolve(__dirname, "../locales/lang.pot"),
|
|
sourceDir: path.resolve(__dirname, "../src"),
|
|
}).build();
|
|
for await (const entry of await glob(
|
|
path.resolve(__dirname, "../locales/*.po")
|
|
)) {
|
|
const lang = basename(entry, ".po");
|
|
const langId = lang.replace("_", "").toLowerCase();
|
|
const parser = new PoParser({
|
|
poPath: path.resolve(__dirname, `../locales/${lang}.po`),
|
|
});
|
|
const items = parser.parse();
|
|
for (const text of Object.keys(items)) {
|
|
if (!this.data[text]) {
|
|
this.data[text] = {};
|
|
}
|
|
if (!this.data[text][langId]) {
|
|
this.data[text][langId] = items[text];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
async build() {
|
|
await this.setData();
|
|
this.data = DeepSort(this.data);
|
|
const jsonPath = path.resolve(
|
|
__dirname,
|
|
"../src/Components/Language/data.json"
|
|
);
|
|
writeFileSync(jsonPath, JSON.stringify(this.data, null, 2));
|
|
}
|
|
}
|
|
new LangBuilder().build();
|