language Switcher added
This commit is contained in:
23
lib/i18n-utils.ts
Normal file
23
lib/i18n-utils.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
"use client"
|
||||
|
||||
import { Locale } from "@/i18n/config"
|
||||
import { useRouter } from "next/navigation"
|
||||
|
||||
export function useChangeLocale() {
|
||||
const router = useRouter()
|
||||
|
||||
const changeLocale = (locale: Locale) => {
|
||||
document.cookie = `NEXT_LOCALE=${locale}; path=/; max-age=31536000`
|
||||
router.refresh()
|
||||
}
|
||||
|
||||
return changeLocale
|
||||
}
|
||||
|
||||
export function getLocaleFromCookie(): Locale {
|
||||
if (typeof document === "undefined") return "uz"
|
||||
|
||||
const cookie = document.cookie.split("; ").find((row) => row.startsWith("NEXT_LOCALE="))
|
||||
|
||||
return (cookie?.split("=")[1] as Locale) || "uz"
|
||||
}
|
||||
Reference in New Issue
Block a user