-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
36 lines (31 loc) · 862 Bytes
/
index.js
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
import i18nextConfig from '../next-i18next.config'
import { useEffect } from 'react'
import { useRouter } from 'next/router'
import languageDetector from '../lib/languageDetector';
export const getStaticProps = () => {
const { locales, defaultLocale } = i18nextConfig.i18n
locales.splice(locales.indexOf(defaultLocale), 1)
locales.push(defaultLocale)
return {
props: {
locales,
},
}
}
const Index = ({ locales }) => {
const router = useRouter()
// language detection
useEffect(() => {
const detectedLng = languageDetector.detect()
for (const locale of locales) {
// eslint-disable-next-line no-undef
if (detectedLng.startsWith(locale)) {
languageDetector.cacheUserLanguage(detectedLng)
router.replace('/' + locale)
return
}
}
}, [])
return <></>
}
export default Index