language Switcher added

This commit is contained in:
nabijonovdavronbek619@gmail.com
2026-01-27 17:36:09 +05:00
parent e87a26d74c
commit de2554a2e7
21 changed files with 830 additions and 32 deletions

23
lib/i18n-utils.ts Normal file
View 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"
}