import { type NextRequest, NextResponse } from "next/server"; import { defaultLocale, isLocale } from "@/i18n/config"; function getPreferredLocale(request: NextRequest) { const acceptLanguage = request.headers.get("accept-language") ?? ""; if (acceptLanguage.toLowerCase().includes("fa")) { return "fa"; } return defaultLocale; } export function proxy(request: NextRequest) { const { pathname } = request.nextUrl; const pathnameHasLocale = isLocale(pathname.split("/")[1]); if (pathnameHasLocale) { return NextResponse.next(); } const locale = getPreferredLocale(request); const url = request.nextUrl.clone(); url.pathname = `/${locale}${pathname === "/" ? "" : pathname}`; return NextResponse.redirect(url); } export const config = { matcher: ["/((?!api|_next|favicon.ico|assets|fonts).*)"], };