Skip to content

Commit 13d364c

Browse files
committed
Add i18nLoader suspense component
1 parent dc8aa0d commit 13d364c

File tree

4 files changed

+28
-16
lines changed

4 files changed

+28
-16
lines changed

public/locales/en/common.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"smiley": ":)",
23
"authorization": "Authorization",
34
"signInHeader": "Sign in with mnemonic",
45
"signIn": "Sign In",

public/locales/ru/common.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"smiley": ":)",
23
"authorization": "Авторизация",
34
"signInHeader": "Войти с мнемоникой",
45
"signIn": "Войти",

src/app/i18n-loader.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import React from 'react'
2+
import i18next from 'i18next'
3+
import Backend from 'i18next-http-backend'
4+
import { initReactI18next } from 'react-i18next'
5+
6+
export const I18nLoader = React.lazy(async () => {
7+
await i18next
8+
.use(initReactI18next)
9+
.use(Backend)
10+
.init({
11+
lng: navigator.language || 'en',
12+
fallbackLng: 'en',
13+
backend: {
14+
loadPath: '/locales/{{lng}}/{{ns}}.json',
15+
},
16+
defaultNS: 'common'
17+
})
18+
19+
return {
20+
default: ({ children }: React.PropsWithChildren) => children
21+
}
22+
})

src/app/main.tsx

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import '@/shared/styles/global.css'
22
import React, { Suspense } from 'react'
33
import ReactDOM from 'react-dom/client'
4-
import i18next from 'i18next'
5-
import Backend from 'i18next-http-backend'
6-
import { initReactI18next } from 'react-i18next'
74
import { Provider } from 'react-redux'
85
import { persistor, store } from '@/shared/store'
96
import { ThemeProvider } from '@/app/theme-provider'
@@ -12,18 +9,7 @@ import { AppLoader } from '@/widgets/loader'
129
import { ErrorBoundary } from '@/app/error-boundary'
1310
import { SodiumLoader } from '@/app/sodium-loader'
1411
import { IndexedDbLoader } from '@/app/indexeddb-loader'
15-
16-
i18next
17-
.use(initReactI18next)
18-
.use(Backend)
19-
.init({
20-
lng: navigator.language || 'en',
21-
fallbackLng: 'en',
22-
backend: {
23-
loadPath: '/locales/{{lng}}/{{ns}}.json',
24-
},
25-
defaultNS: 'common'
26-
})
12+
import { I18nLoader } from '@/app/i18n-loader'
2713

2814
const AppComponent = React.lazy(() => import('@/app/app.tsx'))
2915

@@ -36,7 +22,9 @@ ReactDOM.createRoot(document.getElementById('root')!).render(
3622
<ErrorBoundary>
3723
<SodiumLoader>
3824
<IndexedDbLoader>
39-
<AppComponent />
25+
<I18nLoader>
26+
<AppComponent />
27+
</I18nLoader>
4028
</IndexedDbLoader>
4129
</SodiumLoader>
4230
</ErrorBoundary>

0 commit comments

Comments
 (0)