Add language dropdown localization
This commit is contained in:
@@ -1,9 +1,24 @@
|
||||
import createMiddleware from "next-intl/middleware";
|
||||
import {NextResponse, type NextRequest} from "next/server";
|
||||
import {routing} from "./src/i18n/routing";
|
||||
|
||||
export default createMiddleware(routing);
|
||||
const handleI18nRouting = createMiddleware(routing);
|
||||
|
||||
export default function middleware(request: NextRequest) {
|
||||
const legacyEnglishMarkets = ["/en-ie", "/en-gb", "/en-us"];
|
||||
const pathname = request.nextUrl.pathname;
|
||||
|
||||
for (const legacyPath of legacyEnglishMarkets) {
|
||||
if (pathname === legacyPath || pathname.startsWith(`${legacyPath}/`)) {
|
||||
const url = request.nextUrl.clone();
|
||||
url.pathname = pathname.replace(legacyPath, "/en");
|
||||
return NextResponse.redirect(url);
|
||||
}
|
||||
}
|
||||
|
||||
return handleI18nRouting(request);
|
||||
}
|
||||
|
||||
export const config = {
|
||||
matcher: ["/((?!api|_next|_vercel|.*\\..*).*)"],
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user