-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.js
More file actions
71 lines (71 loc) · 2.18 KB
/
Copy pathapp.js
File metadata and controls
71 lines (71 loc) · 2.18 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const log4js = __importStar(require("log4js"));
const seneca_1 = __importDefault(require("seneca"));
class App {
constructor() {
this.langFile = process.env.LOCALE_PATH;
this.currentLang = 'en';
}
static get instance() {
return this._instance || (this._instance = new this());
}
get controller() {
return this._controller;
}
get storage() {
return this._controller.storage;
}
get seneca() {
return this._seneca;
}
init(controller) {
this._controller = controller;
this._seneca = seneca_1.default();
this.setLocale(this.currentLang);
log4js.configure(`${this.rootPath}/log4js.json`);
this._seneca.use('./plugins/google-translate');
this._seneca.use('./plugins/google-analytics');
}
getLogger(name = 'default') {
return log4js.getLogger(name);
}
get rootPath() {
return __dirname;
}
get lang() {
return this.currentLang;
}
setLocale(lang) {
var i18n_module = require('i18n-nodejs');
this.currentLang = lang;
this.i18n = new i18n_module(lang, this.langFile);
}
localize(msg, args) {
return this.i18n.__(msg, args);
}
track(type, args) {
let types = ['translate'];
if (types.indexOf(type) >= 0) {
if (type == 'translate' && process.env.GA_TRACK_ID) {
args.role = 'analytics';
args.cmd = 'track-translate';
App.instance.seneca.act(args, (err, res) => {
if (err)
App.instance.getLogger().error(err);
});
}
}
}
}
exports.default = App;