mirror of
https://github.com/kmvan/x-prober.git
synced 2026-04-21 16:59:02 +08:00
optimize language builder
This commit is contained in:
@@ -2,13 +2,13 @@
|
|||||||
* @version 1.0.0
|
* @version 1.0.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { writeFileSync } from 'node:fs';
|
import { writeFileSync } from "node:fs";
|
||||||
import path, { basename, dirname } from 'node:path';
|
import { glob } from "node:fs/promises";
|
||||||
import { fileURLToPath } from 'node:url';
|
import path, { basename, dirname } from "node:path";
|
||||||
import DeepSort from 'deep-sort-object';
|
import { fileURLToPath } from "node:url";
|
||||||
import FastGlob from 'fast-glob';
|
import DeepSort from "deep-sort-object";
|
||||||
import { PoParser } from './po-parser.mjs';
|
import { PoParser } from "./po-parser.mjs";
|
||||||
import { PotBuilder } from './pot-builder.mjs';
|
import { PotBuilder } from "./pot-builder.mjs";
|
||||||
|
|
||||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||||
class LangBuilder {
|
class LangBuilder {
|
||||||
@@ -18,18 +18,20 @@ class LangBuilder {
|
|||||||
}
|
}
|
||||||
setData = async () => {
|
setData = async () => {
|
||||||
new PotBuilder({
|
new PotBuilder({
|
||||||
potPath: path.resolve(__dirname, '../locales/lang.pot'),
|
potPath: path.resolve(__dirname, "../locales/lang.pot"),
|
||||||
sourceDir: path.resolve(__dirname, '../src'),
|
sourceDir: path.resolve(__dirname, "../src"),
|
||||||
});
|
});
|
||||||
const files = await FastGlob(path.resolve(__dirname, '../locales/*.po'));
|
for await (const file of glob(path.resolve(__dirname, "../locales/*.po"))) {
|
||||||
for (const file of files) {
|
const lang = basename(file, ".po");
|
||||||
const lang = basename(file, '.po');
|
const langId = lang.replace("_", "").toLowerCase();
|
||||||
const langId = lang.replace('_', '').toLowerCase();
|
|
||||||
const parser = new PoParser({
|
const parser = new PoParser({
|
||||||
poPath: path.resolve(__dirname, `../locales/${lang}.po`),
|
poPath: path.resolve(__dirname, `../locales/${lang}.po`),
|
||||||
});
|
});
|
||||||
const items = parser.parse();
|
const items = parser.parse();
|
||||||
for (const text of Object.keys(items)) {
|
for (const text of Object.keys(items)) {
|
||||||
|
if (text === "") {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (!this.data[text]) {
|
if (!this.data[text]) {
|
||||||
this.data[text] = {};
|
this.data[text] = {};
|
||||||
}
|
}
|
||||||
@@ -44,7 +46,7 @@ class LangBuilder {
|
|||||||
this.data = DeepSort(this.data);
|
this.data = DeepSort(this.data);
|
||||||
const jsonPath = path.resolve(
|
const jsonPath = path.resolve(
|
||||||
__dirname,
|
__dirname,
|
||||||
'../src/Components/Language/data.json'
|
"../src/Components/Language/data.json"
|
||||||
);
|
);
|
||||||
writeFileSync(jsonPath, JSON.stringify(this.data, null, 2));
|
writeFileSync(jsonPath, JSON.stringify(this.data, null, 2));
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user