hloth/session-web
Archived
1
0
Fork 0

Add i18nLoader suspense component

This commit is contained in:
Viktor Shchelochkov 2024-05-02 05:44:22 +04:00
commit 13d364c684
Signed by: hloth
GPG key ID: A7EA9B54F67F9685
4 changed files with 28 additions and 16 deletions

View file

@ -1,4 +1,5 @@
{
"smiley": ":)",
"authorization": "Authorization",
"signInHeader": "Sign in with mnemonic",
"signIn": "Sign In",

View file

@ -1,4 +1,5 @@
{
"smiley": ":)",
"authorization": "Авторизация",
"signInHeader": "Войти с мнемоникой",
"signIn": "Войти",

22
src/app/i18n-loader.tsx Normal file
View file

@ -0,0 +1,22 @@
import React from 'react'
import i18next from 'i18next'
import Backend from 'i18next-http-backend'
import { initReactI18next } from 'react-i18next'
export const I18nLoader = React.lazy(async () => {
await i18next
.use(initReactI18next)
.use(Backend)
.init({
lng: navigator.language || 'en',
fallbackLng: 'en',
backend: {
loadPath: '/locales/{{lng}}/{{ns}}.json',
},
defaultNS: 'common'
})
return {
default: ({ children }: React.PropsWithChildren) => children
}
})

View file

@ -1,9 +1,6 @@
import '@/shared/styles/global.css'
import React, { Suspense } from 'react'
import ReactDOM from 'react-dom/client'
import i18next from 'i18next'
import Backend from 'i18next-http-backend'
import { initReactI18next } from 'react-i18next'
import { Provider } from 'react-redux'
import { persistor, store } from '@/shared/store'
import { ThemeProvider } from '@/app/theme-provider'
@ -12,18 +9,7 @@ import { AppLoader } from '@/widgets/loader'
import { ErrorBoundary } from '@/app/error-boundary'
import { SodiumLoader } from '@/app/sodium-loader'
import { IndexedDbLoader } from '@/app/indexeddb-loader'
i18next
.use(initReactI18next)
.use(Backend)
.init({
lng: navigator.language || 'en',
fallbackLng: 'en',
backend: {
loadPath: '/locales/{{lng}}/{{ns}}.json',
},
defaultNS: 'common'
})
import { I18nLoader } from '@/app/i18n-loader'
const AppComponent = React.lazy(() => import('@/app/app.tsx'))
@ -36,7 +22,9 @@ ReactDOM.createRoot(document.getElementById('root')!).render(
<ErrorBoundary>
<SodiumLoader>
<IndexedDbLoader>
<AppComponent />
<I18nLoader>
<AppComponent />
</I18nLoader>
</IndexedDbLoader>
</SodiumLoader>
</ErrorBoundary>