-
Notifications
You must be signed in to change notification settings - Fork 60
/
locale.js
53 lines (48 loc) · 1.16 KB
/
locale.js
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
'use strict';
const path = require('path');
const {app} = require('electron');
const {appReady} = require('electron-util');
const ipc = require('electron-better-ipc');
const i18next = require('i18next');
const i18nextBackend = require('i18next-sync-fs-backend');
const {isDevelopment} = require('./util-common');
const config = require('./config');
i18next
.use(i18nextBackend)
.init({
fallbackLng: 'en-US',
ns: [
'app',
'chart',
'common',
'dashboard',
'exchange',
'forgot-password',
'login',
'menu',
'nav',
'portfolio',
'settings',
'swap',
'trades',
],
initImmediate: false,
backend: {
loadPath: path.join(__dirname, 'locales', '{{lng}}', '{{ns}}.json'),
jsonIndent: 4,
},
});
(async () => {
if (isDevelopment && config.has('debug_forcedLanguage')) {
i18next.changeLanguage(config.get('debug_forcedLanguage'));
return;
}
await appReady;
i18next.changeLanguage(app.getLocale());
})();
ipc.answerRenderer('get-translations', async () => {
await appReady;
return i18next;
});
exports.i18n = i18next;
exports.translate = namespaces => namespaces ? i18next.getFixedT(null, namespaces) : i18next.t.bind(i18next);