@grandlinex/bundle-multilang
Version:
> Multilang support for GrandLineX
33 lines (32 loc) • 1.19 kB
JavaScript
import { CoreBundleModule } from '@grandlinex/core';
import LangClient from './client/LangClient.js';
import LangDb from './db/LangDb.js';
export default class LangModule extends CoreBundleModule {
constructor(kernel, defaultLang, dbFc) {
super('lang', kernel);
this.defaultLang = defaultLang;
this.setDb(new LangDb(dbFc(this)));
}
async initModule() {
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() {
return Promise.resolve(undefined);
}
}