Implement i18n with German and English support (default DE)

This commit is contained in:
2026-01-12 21:38:05 +01:00
parent a60d456b3b
commit 62e1f5f1b4
14 changed files with 471 additions and 228 deletions

30
middleware.ts Normal file
View File

@@ -0,0 +1,30 @@
import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";
const locales = ["en", "de"];
const defaultLocale = "de";
export function middleware(request: NextRequest) {
const { pathname } = request.nextUrl;
// Check if there is any supported locale in the pathname
const pathnameHasLocale = locales.some(
(locale) => pathname.startsWith(`/${locale}/`) || pathname === `/${locale}`
);
if (pathnameHasLocale) return;
// Redirect if there is no locale
const locale = defaultLocale; // For simplicity, we default to 'de' as requested
request.nextUrl.pathname = `/${locale}${pathname}`;
// Keep searching if the URL changes
return NextResponse.redirect(request.nextUrl);
}
export const config = {
matcher: [
// Skip all internal paths (_next)
"/((?!_next|api|public|manifest|icon|file|globe|next|vercel|window).*)",
],
};