2022-10-10 09:43:13 +08:00
|
|
|
import { LanguageTag } from '@logto/language-kit';
|
2022-08-30 16:53:49 +08:00
|
|
|
import resources from '@logto/phrases';
|
2022-02-28 22:18:01 +08:00
|
|
|
import i18next from 'i18next';
|
|
|
|
import LanguageDetector from 'i18next-browser-languagedetector';
|
|
|
|
import { initReactI18next } from 'react-i18next';
|
|
|
|
|
2022-10-10 09:43:13 +08:00
|
|
|
const initI18n = async (language?: LanguageTag) =>
|
2022-02-28 22:18:01 +08:00
|
|
|
i18next
|
|
|
|
.use(initReactI18next)
|
|
|
|
.use(LanguageDetector)
|
|
|
|
.init({
|
|
|
|
resources,
|
|
|
|
fallbackLng: 'en',
|
|
|
|
interpolation: {
|
|
|
|
escapeValue: false,
|
|
|
|
},
|
2022-07-07 22:43:26 +08:00
|
|
|
lng: language,
|
2022-07-07 11:08:07 +08:00
|
|
|
detection: {
|
|
|
|
lookupLocalStorage: 'i18nextLogtoAcLng',
|
|
|
|
lookupSessionStorage: 'i18nextLogtoAcLng',
|
|
|
|
},
|
2022-02-28 22:18:01 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
export default initI18n;
|