@fabrix/spool-i18n
Version:
Spool - i18n for Fabrix
72 lines (71 loc) • 2.37 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const extension_1 = require("@fabrix/fabrix/dist/common/spools/extension");
const i18next_1 = require("i18next");
const config = require("./config/index");
const pkg = require("../package.json");
class I18nSpool extends extension_1.ExtensionSpool {
constructor(app) {
super(app, {
config: config,
pkg: pkg,
api: {}
});
this.extensions = {
__: {
get: () => {
return this.__;
},
set: (newValue) => {
throw new Error('__ can not be set through FabrixApp, check spool-i18n instead');
},
enumerable: true,
configurable: true
}
};
return this;
}
initI18n(i18nConfig) {
return __awaiter(this, void 0, void 0, function* () {
return i18next_1.default.init(i18nConfig)
.then(t => {
this._translate = t;
return this._translate = t;
});
});
}
get __() {
if (this._translate) {
return this._translate;
}
else {
throw new Error('i18n has not yet been initialized');
}
}
validate() {
}
configure() {
}
initialize() {
return __awaiter(this, void 0, void 0, function* () {
yield this.initI18n(this.app.config.get('i18n'));
});
}
unload() {
return __awaiter(this, void 0, void 0, function* () {
});
}
sanity() {
return __awaiter(this, void 0, void 0, function* () {
});
}
}
exports.I18nSpool = I18nSpool;