Add i18n support with NL/EN language switching (ST-001)
- 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>
This commit is contained in:
parent
61e603b5d7
commit
d352a7d496
13 changed files with 540 additions and 177 deletions
27
middleware.ts
Normal file
27
middleware.ts
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
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).*)"],
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue