UNPKG

@grandlinex/bundle-multilang

Version:
39 lines (38 loc) 1.51 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const core_1 = require("@grandlinex/core"); const LangClient_js_1 = __importDefault(require("./client/LangClient.js")); const LangDb_js_1 = __importDefault(require("./db/LangDb.js")); class LangModule extends core_1.CoreBundleModule { constructor(kernel, defaultLang, dbFc) { super('lang', kernel); this.defaultLang = defaultLang; this.setDb(new LangDb_js_1.default(dbFc(this))); } async initModule() { const client = new LangClient_js_1.default(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_js_1.default.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); } } exports.default = LangModule;