zumito-framework 1.1.46 → 1.1.47
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/types/Module.d.ts +2 -1
- package/dist/types/Module.js +22 -12
- package/package.json +1 -1
package/dist/types/Module.d.ts
CHANGED
|
@@ -18,7 +18,8 @@ export declare abstract class Module {
|
|
|
18
18
|
registerDiscordEvent(frameworkEvent: FrameworkEvent): void;
|
|
19
19
|
parseEventArgs(args: any[]): any;
|
|
20
20
|
getEvents(): Map<string, FrameworkEvent>;
|
|
21
|
-
registerTranslations(): Promise<void>;
|
|
21
|
+
registerTranslations(subpath?: string): Promise<void>;
|
|
22
|
+
loadTranslationFile(subpath: string, file: string): Promise<any>;
|
|
22
23
|
parseTranslation(path: string, lang: string, json: any): any;
|
|
23
24
|
registerModels(): Promise<void>;
|
|
24
25
|
getModels(): Map<string, any>;
|
package/dist/types/Module.js
CHANGED
|
@@ -137,25 +137,35 @@ export class Module {
|
|
|
137
137
|
getEvents() {
|
|
138
138
|
return this.events;
|
|
139
139
|
}
|
|
140
|
-
async registerTranslations() {
|
|
141
|
-
if (!fs.existsSync(path.join(this.path, 'translations')))
|
|
140
|
+
async registerTranslations(subpath = '') {
|
|
141
|
+
if (!fs.existsSync(path.join(this.path, 'translations', subpath)))
|
|
142
142
|
return;
|
|
143
|
-
let files = fs.readdirSync(path.join(this.path, 'translations'));
|
|
143
|
+
let files = fs.readdirSync(path.join(this.path, 'translations', subpath));
|
|
144
144
|
for (let file of files) {
|
|
145
145
|
if (file.endsWith('.json')) {
|
|
146
|
-
let json = await
|
|
147
|
-
assert: {
|
|
148
|
-
type: "json",
|
|
149
|
-
},
|
|
150
|
-
}).catch(e => {
|
|
151
|
-
console.error(`[🔄🔴 ] Error loading ${file.slice(0, -5)} translations on module ${this.constructor.name}`);
|
|
152
|
-
console.log(boxen(e + '\n' + e.name + '\n' + e.stack, { padding: 1 }));
|
|
153
|
-
});
|
|
146
|
+
let json = await this.loadTranslationFile(subpath, file);
|
|
154
147
|
let lang = file.slice(0, -5);
|
|
155
|
-
|
|
148
|
+
subpath = subpath ? subpath.replaceAll('/', '.') + '.' : '';
|
|
149
|
+
this.parseTranslation(subpath, lang, json);
|
|
150
|
+
}
|
|
151
|
+
else if (fs.lstatSync(path.join(this.path, 'translations', file)).isDirectory()) {
|
|
152
|
+
await this.registerTranslations(path.join(subpath, file));
|
|
156
153
|
}
|
|
157
154
|
}
|
|
158
155
|
}
|
|
156
|
+
async loadTranslationFile(subpath, file) {
|
|
157
|
+
if (subpath)
|
|
158
|
+
subpath = subpath + '/';
|
|
159
|
+
let json = await import('file://' + `${this.path}/translations/${subpath}${file}`, {
|
|
160
|
+
assert: {
|
|
161
|
+
type: "json",
|
|
162
|
+
},
|
|
163
|
+
}).catch(e => {
|
|
164
|
+
console.error(`[🔄🔴 ] Error loading ${file.slice(0, -5)} translations on module ${this.constructor.name}`);
|
|
165
|
+
console.error(e + '\n' + e.name + '\n' + e.stack);
|
|
166
|
+
});
|
|
167
|
+
return json.default;
|
|
168
|
+
}
|
|
159
169
|
parseTranslation(path, lang, json) {
|
|
160
170
|
if (typeof json === 'object') {
|
|
161
171
|
for (let key in json) {
|