Remove unnecessary i18next-http-backend

This commit is contained in:
Haishan 2023-01-30 23:10:31 +08:00
parent a24a74e9e1
commit 313a182a46
3 changed files with 27 additions and 77 deletions

View file

@ -42,7 +42,6 @@
"history": "5.3.0", "history": "5.3.0",
"i18next": "22.4.9", "i18next": "22.4.9",
"i18next-browser-languagedetector": "7.0.1", "i18next-browser-languagedetector": "7.0.1",
"i18next-http-backend": "2.1.1",
"immer": "9.0.19", "immer": "9.0.19",
"invariant": "^2.2.4", "invariant": "^2.2.4",
"lodash-es": "^4.17.21", "lodash-es": "^4.17.21",

View file

@ -36,7 +36,6 @@ specifiers:
history: 5.3.0 history: 5.3.0
i18next: 22.4.9 i18next: 22.4.9
i18next-browser-languagedetector: 7.0.1 i18next-browser-languagedetector: 7.0.1
i18next-http-backend: 2.1.1
immer: 9.0.19 immer: 9.0.19
invariant: ^2.2.4 invariant: ^2.2.4
lodash-es: ^4.17.21 lodash-es: ^4.17.21
@ -90,7 +89,6 @@ dependencies:
history: 5.3.0 history: 5.3.0
i18next: 22.4.9 i18next: 22.4.9
i18next-browser-languagedetector: 7.0.1 i18next-browser-languagedetector: 7.0.1
i18next-http-backend: 2.1.1
immer: 9.0.19 immer: 9.0.19
invariant: 2.2.4 invariant: 2.2.4
lodash-es: 4.17.21 lodash-es: 4.17.21
@ -4090,14 +4088,6 @@ packages:
yaml: 1.10.2 yaml: 1.10.2
dev: true dev: true
/cross-fetch/3.1.5:
resolution: {integrity: sha512-lvb1SBsI0Z7GDwmuid+mU3kWVBwTVUbe7S0H52yaaAdQOXq2YktTCZdlAcNKFzE6QtRz0snpw9bNiPeOIkkQvw==}
dependencies:
node-fetch: 2.6.7
transitivePeerDependencies:
- encoding
dev: false
/cross-spawn/7.0.3: /cross-spawn/7.0.3:
resolution: {integrity: sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==} resolution: {integrity: sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==}
engines: {node: '>= 8'} engines: {node: '>= 8'}
@ -5102,14 +5092,6 @@ packages:
'@babel/runtime': 7.20.13 '@babel/runtime': 7.20.13
dev: false dev: false
/i18next-http-backend/2.1.1:
resolution: {integrity: sha512-jByfUCDVgQ8+/Wens7queQhYYvMcGTW/lR4IJJNEDDXnmqjLrwi8ubXKpmp76/JIWEZHffNdWqnxFJcTVGeaOw==}
dependencies:
cross-fetch: 3.1.5
transitivePeerDependencies:
- encoding
dev: false
/i18next/22.4.9: /i18next/22.4.9:
resolution: {integrity: sha512-8gWMmUz460KJDQp/ob3MNUX84cVuDRY9PLFPnV8d+Qezz/6dkjxwOaH70xjrCNDO+JrUL25iXfAIN9wUkInNZw==} resolution: {integrity: sha512-8gWMmUz460KJDQp/ob3MNUX84cVuDRY9PLFPnV8d+Qezz/6dkjxwOaH70xjrCNDO+JrUL25iXfAIN9wUkInNZw==}
dependencies: dependencies:
@ -5633,18 +5615,6 @@ packages:
resolution: {integrity: sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==} resolution: {integrity: sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==}
dev: true dev: true
/node-fetch/2.6.7:
resolution: {integrity: sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==}
engines: {node: 4.x || >=6.0.0}
peerDependencies:
encoding: ^0.1.0
peerDependenciesMeta:
encoding:
optional: true
dependencies:
whatwg-url: 5.0.0
dev: false
/node-releases/2.0.6: /node-releases/2.0.6:
resolution: {integrity: sha512-PiVXnNuFm5+iYkLBNeq5211hvO38y63T0i2KKh2KnUs3RpzJ+JtODFjkD8yjLwnDkTYF1eKXheUwdssR+NRZdg==} resolution: {integrity: sha512-PiVXnNuFm5+iYkLBNeq5211hvO38y63T0i2KKh2KnUs3RpzJ+JtODFjkD8yjLwnDkTYF1eKXheUwdssR+NRZdg==}
dev: true dev: true
@ -6534,10 +6504,6 @@ packages:
is-number: 7.0.0 is-number: 7.0.0
dev: true dev: true
/tr46/0.0.3:
resolution: {integrity: sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==}
dev: false
/tr46/1.0.1: /tr46/1.0.1:
resolution: {integrity: sha512-dTpowEjclQ7Kgx5SdBkqRzVhERQXov8/l9Ft9dVM9fmg0W0KQSVaXX9T4i6twCPNtYiZM53lpSSUAwJbFPOHxA==} resolution: {integrity: sha512-dTpowEjclQ7Kgx5SdBkqRzVhERQXov8/l9Ft9dVM9fmg0W0KQSVaXX9T4i6twCPNtYiZM53lpSSUAwJbFPOHxA==}
dependencies: dependencies:
@ -6753,21 +6719,10 @@ packages:
loose-envify: 1.4.0 loose-envify: 1.4.0
dev: false dev: false
/webidl-conversions/3.0.1:
resolution: {integrity: sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==}
dev: false
/webidl-conversions/4.0.2: /webidl-conversions/4.0.2:
resolution: {integrity: sha512-YQ+BmxuTgd6UXZW3+ICGfyqRyHXVlD5GtQr5+qjiNW7bF0cqrzX500HVXPBOvgXb5YnzDd+h0zqyv61KUD7+Sg==} resolution: {integrity: sha512-YQ+BmxuTgd6UXZW3+ICGfyqRyHXVlD5GtQr5+qjiNW7bF0cqrzX500HVXPBOvgXb5YnzDd+h0zqyv61KUD7+Sg==}
dev: true dev: true
/whatwg-url/5.0.0:
resolution: {integrity: sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==}
dependencies:
tr46: 0.0.3
webidl-conversions: 3.0.1
dev: false
/whatwg-url/7.1.0: /whatwg-url/7.1.0:
resolution: {integrity: sha512-WUu7Rg1DroM7oQvGWfOiAK21n74Gg+T4elXEQYkOhtyLeWiJFoOGLXPKI/9gzIie9CtwVLm8wtw6YJdKyxSjeg==} resolution: {integrity: sha512-WUu7Rg1DroM7oQvGWfOiAK21n74Gg+T4elXEQYkOhtyLeWiJFoOGLXPKI/9gzIie9CtwVLm8wtw6YJdKyxSjeg==}
dependencies: dependencies:

View file

@ -1,44 +1,40 @@
import type { ReadCallback } from 'i18next';
import i18next from 'i18next'; import i18next from 'i18next';
import LanguageDetector from 'i18next-browser-languagedetector'; import LanguageDetector from 'i18next-browser-languagedetector';
import HttpBackend from 'i18next-http-backend';
import { initReactI18next } from 'react-i18next'; import { initReactI18next } from 'react-i18next';
type BackendRequestCallback = (err: null, result: { status: number; data: any }) => void; const LngBackend = {
type: 'backend' as const,
read: (
lng: string,
_namespace: string,
callback: ReadCallback,
) => {
let p: PromiseLike<{ data: any }>;
switch (lng) {
case 'zh':
case 'zh-CN':
p = import('src/i18n/zh');
break;
case 'en':
default:
p = import('src/i18n/en');
break;
}
if (p) {
p.then(d => callback(null, d.data), err => callback(err, null));
} else {
callback(new Error(`unable to load translation file for language ${lng}`), null)
}
}
}
i18next i18next
.use(HttpBackend)
.use(initReactI18next) .use(initReactI18next)
.use(LanguageDetector) .use(LanguageDetector)
.use(LngBackend)
.init({ .init({
debug: process.env.NODE_ENV === 'development', debug: process.env.NODE_ENV === 'development',
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 = import('src/i18n/zh');
break;
case '/__en/translation.json':
default:
p = import('src/i18n/en');
break;
}
if (p) {
p.then((mod) => {
callback(null, { status: 200, data: mod.data });
});
}
},
},
fallbackLng: 'en', fallbackLng: 'en',
interpolation: { interpolation: {
escapeValue: false, escapeValue: false,