mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-18 14:56:59 +08:00
feat: init languageDetector
This commit is contained in:
@@ -19,6 +19,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"i18next": "^21.9.1",
|
"i18next": "^21.9.1",
|
||||||
|
"i18next-browser-languagedetector": "^7.0.1",
|
||||||
"prettier": "^2.7.1",
|
"prettier": "^2.7.1",
|
||||||
"react-i18next": "^11.18.4"
|
"react-i18next": "^11.18.4"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import i18next, { Resource } from 'i18next';
|
import i18next, { Resource } from 'i18next';
|
||||||
import { Trans, initReactI18next, useTranslation } from 'react-i18next';
|
import { Trans, initReactI18next, useTranslation } from 'react-i18next';
|
||||||
|
import detector from 'i18next-browser-languagedetector';
|
||||||
import { LOCALES } from './resources/index.js';
|
import { LOCALES } from './resources/index.js';
|
||||||
import type en_US from './resources/en.json';
|
import type en_US from './resources/en.json';
|
||||||
|
|
||||||
@@ -45,15 +46,18 @@ const language = standardizeLocale(
|
|||||||
);
|
);
|
||||||
|
|
||||||
const i18n = i18next.createInstance();
|
const i18n = i18next.createInstance();
|
||||||
i18n.use(initReactI18next).init({
|
i18n
|
||||||
lng: language,
|
.use(detector)
|
||||||
fallbackLng,
|
.use(initReactI18next)
|
||||||
debug: false,
|
.init({
|
||||||
resources,
|
lng: language,
|
||||||
interpolation: {
|
fallbackLng,
|
||||||
escapeValue: false, // not needed for react as it escapes by default
|
debug: false,
|
||||||
},
|
resources,
|
||||||
});
|
interpolation: {
|
||||||
|
escapeValue: false, // not needed for react as it escapes by default
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
i18n.on('languageChanged', () => {
|
i18n.on('languageChanged', () => {
|
||||||
// localStorage.setItem(STORAGE_KEY, lng);
|
// localStorage.setItem(STORAGE_KEY, lng);
|
||||||
|
|||||||
8
pnpm-lock.yaml
generated
8
pnpm-lock.yaml
generated
@@ -162,11 +162,13 @@ importers:
|
|||||||
specifiers:
|
specifiers:
|
||||||
'@types/prettier': ^2.7.2
|
'@types/prettier': ^2.7.2
|
||||||
i18next: ^21.9.1
|
i18next: ^21.9.1
|
||||||
|
i18next-browser-languagedetector: ^7.0.1
|
||||||
prettier: ^2.7.1
|
prettier: ^2.7.1
|
||||||
react-i18next: ^11.18.4
|
react-i18next: ^11.18.4
|
||||||
typescript: ^4.8.4
|
typescript: ^4.8.4
|
||||||
dependencies:
|
dependencies:
|
||||||
i18next: 21.10.0
|
i18next: 21.10.0
|
||||||
|
i18next-browser-languagedetector: 7.0.1
|
||||||
prettier: 2.7.1
|
prettier: 2.7.1
|
||||||
react-i18next: 11.18.6_i18next@21.10.0
|
react-i18next: 11.18.6_i18next@21.10.0
|
||||||
devDependencies:
|
devDependencies:
|
||||||
@@ -5610,6 +5612,12 @@ packages:
|
|||||||
hasBin: true
|
hasBin: true
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
|
/i18next-browser-languagedetector/7.0.1:
|
||||||
|
resolution: {integrity: sha512-Pa5kFwaczXJAeHE56CHG2aWzFBMJNUNghf0Pm4SwSrEMps/PTKqW90EYWlIvhuYStf3Sn1K0vw+gH3+TLdkH1g==}
|
||||||
|
dependencies:
|
||||||
|
'@babel/runtime': 7.20.7
|
||||||
|
dev: false
|
||||||
|
|
||||||
/i18next/21.10.0:
|
/i18next/21.10.0:
|
||||||
resolution: {integrity: sha512-YeuIBmFsGjUfO3qBmMOc0rQaun4mIpGKET5WDwvu8lU7gvwpcariZLNtL0Fzj+zazcHUrlXHiptcFhBMFaxzfg==}
|
resolution: {integrity: sha512-YeuIBmFsGjUfO3qBmMOc0rQaun4mIpGKET5WDwvu8lU7gvwpcariZLNtL0Fzj+zazcHUrlXHiptcFhBMFaxzfg==}
|
||||||
dependencies:
|
dependencies:
|
||||||
|
|||||||
Reference in New Issue
Block a user