- Add English translations to cv-data.ts with getCvData(lang) helper - Create app/[lang]/ routing with static generation for nl and en - Add language switcher in nav (NL / EN toggle) - Add middleware for Accept-Language auto-redirect on root path - Root layout reads x-lang header to set <html lang> correctly - All components accept lang prop and render translated content Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
27 lines
918 B
TypeScript
27 lines
918 B
TypeScript
import { NextResponse } from "next/server";
|
|
import type { NextRequest } from "next/server";
|
|
|
|
export function middleware(request: NextRequest) {
|
|
const { pathname } = request.nextUrl;
|
|
|
|
// Detect lang from path for the x-lang header
|
|
const lang = pathname.startsWith("/en") ? "en" : "nl";
|
|
|
|
// On root path: redirect based on Accept-Language
|
|
if (pathname === "/") {
|
|
const acceptLanguage = request.headers.get("accept-language") ?? "";
|
|
const prefersEnglish =
|
|
acceptLanguage.includes("en") && !acceptLanguage.startsWith("nl");
|
|
const redirectLang = prefersEnglish ? "en" : "nl";
|
|
return NextResponse.redirect(new URL(`/${redirectLang}`, request.url));
|
|
}
|
|
|
|
// Pass x-lang header so root layout can set <html lang>
|
|
const response = NextResponse.next();
|
|
response.headers.set("x-lang", lang);
|
|
return response;
|
|
}
|
|
|
|
export const config = {
|
|
matcher: ["/((?!_next|images|favicon.ico).*)"],
|
|
};
|