init commit,
This commit is contained in:
32
03_source/frontend/src/locales/i18n-provider.tsx
Normal file
32
03_source/frontend/src/locales/i18n-provider.tsx
Normal file
@@ -0,0 +1,32 @@
|
||||
import i18next from 'i18next';
|
||||
import { getStorage } from 'minimal-shared/utils';
|
||||
import resourcesToBackend from 'i18next-resources-to-backend';
|
||||
import LanguageDetector from 'i18next-browser-languagedetector/cjs';
|
||||
import { initReactI18next, I18nextProvider as Provider } from 'react-i18next';
|
||||
|
||||
import { i18nOptions, fallbackLng } from './locales-config';
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* [1] localStorage
|
||||
* Auto detection:
|
||||
* const lng = getStorage('i18nextLng')
|
||||
*/
|
||||
const lng = getStorage('i18nextLng', fallbackLng) as string;
|
||||
|
||||
i18next
|
||||
.use(LanguageDetector)
|
||||
.use(initReactI18next)
|
||||
.use(resourcesToBackend((lang: string, ns: string) => import(`./langs/${lang}/${ns}.json`)))
|
||||
.init({ ...i18nOptions(lng), detection: { caches: ['localStorage'] } });
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
type Props = {
|
||||
children: React.ReactNode;
|
||||
};
|
||||
|
||||
export function I18nProvider({ children }: Props) {
|
||||
return <Provider i18n={i18next}>{children}</Provider>;
|
||||
}
|
Reference in New Issue
Block a user