import { NextResponse, type NextRequest } from "next/server"; import { locales, defaultLocale } from "@/i18n/config"; const PUBLIC_FILE = /\.(.*)$/; /** * Sends every un-prefixed path to a locale-prefixed one. Today `fa` is the only * shipped locale; once `en` / `ar` are added, negotiate on `Accept-Language` * here and the rest of the app needs no changes. */ export function middleware(request: NextRequest) { const { pathname } = request.nextUrl; const hasLocale = locales.some( (locale) => pathname === `/${locale}` || pathname.startsWith(`/${locale}/`) ); if (hasLocale || PUBLIC_FILE.test(pathname)) return NextResponse.next(); const url = request.nextUrl.clone(); url.pathname = `/${defaultLocale}${pathname === "/" ? "" : pathname}`; return NextResponse.redirect(url); } export const config = { matcher: ["/((?!api|_next/static|_next/image|images|fonts|favicon.ico).*)"], };