generated from hemengke1997/ts-starter
-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.tsx
64 lines (61 loc) · 1.49 KB
/
main.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import React from 'react'
import { initReactI18next } from 'react-i18next'
import i18next from 'i18next'
import ReactDOM from 'react-dom/client'
import { i18nAlly } from 'vite-plugin-i18n-ally/client'
import App from './App'
import { fallbackLng, lookupTarget } from './const'
import './index.css'
const root = ReactDOM.createRoot(document.querySelector('#root') as HTMLElement)
const { asyncLoadResource } = i18nAlly({
onInit({ language }) {
i18next.use(initReactI18next).init({
lng: language,
returnNull: false,
react: {
useSuspense: true,
},
debug: import.meta.env.DEV,
resources: {},
nsSeparator: '.',
keySeparator: '.',
interpolation: {
escapeValue: false,
},
lowerCaseLng: true,
fallbackLng,
})
},
onInited(...args) {
console.log(args, 'onInited')
root.render(
<React.StrictMode>
<App />
</React.StrictMode>,
)
},
onResourceLoaded: (resources, { language }) => {
Object.keys(resources).forEach((ns) => {
i18next.addResourceBundle(language, ns, resources[ns])
})
},
fallbackLng,
detection: [
{
detect: 'querystring',
lookup: lookupTarget,
},
{
detect: 'cookie',
lookup: 'with-namespace-lang',
},
{
detect: 'htmlTag',
},
],
})
const changeLanguage = i18next.changeLanguage
i18next.changeLanguage = async (lang: string, ...args) => {
await asyncLoadResource(lang)
return changeLanguage(lang, ...args)
}