-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: default
languageDetection()
added
- Loading branch information
Xairoo
committed
Oct 30, 2022
1 parent
ff18d74
commit 64aba11
Showing
3 changed files
with
42 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,5 @@ | ||
import { useEffect } from "react"; | ||
import { useRouter } from "next/router"; | ||
import { cookieName, useTranslation } from "next-i18next-static-site"; | ||
import Cookies from "js-cookie"; | ||
import { languageDetection } from "next-i18next-static-site"; | ||
|
||
export default function Home() { | ||
const { i18n } = useTranslation(); | ||
const router = useRouter(); | ||
|
||
useEffect(() => { | ||
const cookieLocale = Cookies.get(cookieName); | ||
|
||
let browserLocale = | ||
navigator.languages && navigator.languages.length | ||
? navigator.languages[0] | ||
: navigator.language; | ||
|
||
browserLocale = browserLocale.slice(0, 2); | ||
|
||
if (cookieLocale && cookieLocale !== "false") { | ||
router.push("/" + cookieLocale); | ||
} else if (browserLocale) { | ||
router.push("/" + browserLocale); | ||
} else { | ||
router.push("/" + i18n.language); | ||
} | ||
}, [router, i18n.language]); | ||
|
||
return null; | ||
languageDetection(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters