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
|
import i18next from 'i18next';
import LanguageDetector from 'i18next-browser-languagedetector';
import HttpBackend from 'i18next-http-backend';
import { initReactI18next } from 'react-i18next';
const allLocales = {
zh: import('src/i18n/zh'),
en: import('src/i18n/en'),
};
type BackendRequestCallback = (
err: null,
result: { status: number; data: any }
) => void;
i18next
.use(HttpBackend)
.use(initReactI18next)
.use(LanguageDetector)
.init({
debug: process.env.NODE_ENV === 'development',
// resources,
backend: {
loadPath: '/__{{lng}}/{{ns}}.json',
request: function (
_options: any,
url: string,
_payload: any,
callback: BackendRequestCallback
) {
let p: PromiseLike<{ data: any }>;
switch (url) {
case '/__zh/translation.json':
case '/__zh-CN/translation.json':
p = allLocales.zh;
break;
case '/__en/translation.json':
default:
p = allLocales.en;
break;
}
if (p) {
p.then((mod) => {
callback(null, { status: 200, data: mod.data });
});
}
},
},
supportedLngs: ['en', 'zh'],
fallbackLng: 'en',
interpolation: {
escapeValue: false,
},
});
if (process.env.NODE_ENV === 'development') {
window.i18n = i18next;
}
export default i18next;
|