-
Notifications
You must be signed in to change notification settings - Fork 0
/
i18n.js
41 lines (36 loc) · 994 Bytes
/
i18n.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
const i18next = require('i18next');
const middleware = require('i18next-http-middleware');
const Backend = require('i18next-fs-backend');
module.exports = (callback) => {
return new Promise((resolve, reject) => {
// Initialize i18next
i18next
.use(Backend)
.use(middleware.LanguageDetector)
.init({
// debug: true,
fallbackLng: 'en',
detection: {
order: ['querystring', 'cookie', 'header'],
lookupQuerystring: 'lang',
caches: ['cookie']
},
preload: ['en', 'it'],
backend: {
loadPath: __dirname + '/locales/{{lng}}/{{ns}}.json',
},
// ...otherOptions
}, (err, t) => {
if (err) {
if (callback) {
callback(err);
}
return reject(err);
}
if (callback) {
callback(null, i18next);
}
resolve(i18next);
});
});
};