-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLangModule.ts
50 lines (45 loc) · 1.33 KB
/
LangModule.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { CoreBundleModule, ICoreKernel, IDataBase } from '@grandlinex/core';
import LangClient from './client/LangClient.js';
import LangDb from './db/LangDb.js';
export default class LangModule extends CoreBundleModule<
ICoreKernel<any>,
LangDb,
LangClient,
null,
null
> {
defaultLang: string;
constructor(
kernel: ICoreKernel<any>,
defaultLang: string,
dbFc: (
mod: CoreBundleModule<any, any, any, any, any>,
) => IDataBase<any, any>,
) {
super('lang', kernel);
this.defaultLang = defaultLang;
this.setDb(new LangDb(dbFc(this)));
}
async initModule(): Promise<void> {
const client = new LangClient(this);
this.setClient(client);
}
async beforeServiceStart() {
const store = this.getKernel().getConfigStore();
const client = this.getClient();
const isInit = await this.getDb().getConfig('init');
if (!isInit) {
const storePath = store.get(LangClient.STORE_TRANSLATION_PATH);
if (!storePath) {
throw this.lError('No Translation path defined');
}
await client.loadLangFromFolder(storePath);
await client.setDbLang(this.defaultLang);
await this.getDb().setConfig('init', 'true');
}
await this.getKernel().triggerEvent('lang-loaded');
}
initBundleModule(): Promise<void> {
return Promise.resolve(undefined);
}
}