The site now exists in German (at the root, with /impressum and /datenschutz) and English (/en). A request without a language follows the visitor's choice from the language switch, then the browser language, then German; the old English legal addresses move to /en for good. All visible texts are data in src/content/de.ts and en.ts, so components hold none of their own. The header carries a DE/EN switch whose bit curtain covers the page while it is swapped and reopens at the same reading position. Title, description, canonical, hreflang, Open Graph, the share image, the sitemap and the structured data are per language. The privacy notice now describes the cookie that remembers the chosen language. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
38 lines
1.2 KiB
TypeScript
38 lines
1.2 KiB
TypeScript
import { NextResponse, type NextRequest } from "next/server";
|
|
import { LOCALE_COOKIE } from "@/src/domain/locale";
|
|
import { routeRequest } from "@/src/domain/routes";
|
|
|
|
const PERMANENT = 308;
|
|
const TEMPORARY = 307;
|
|
|
|
/**
|
|
* Picks the language of a request and maps the public addresses onto the app
|
|
* directory. All decisions are made in src/domain/routes.ts; this only carries
|
|
* them out.
|
|
*/
|
|
export function proxy(request: NextRequest) {
|
|
const decision = routeRequest({
|
|
pathname: request.nextUrl.pathname,
|
|
cookie: request.cookies.get(LOCALE_COOKIE)?.value,
|
|
acceptLanguage: request.headers.get("accept-language"),
|
|
});
|
|
|
|
const url = request.nextUrl.clone();
|
|
url.pathname = decision.to;
|
|
const response =
|
|
decision.kind === "redirect"
|
|
? NextResponse.redirect(url, decision.permanent ? PERMANENT : TEMPORARY)
|
|
: NextResponse.rewrite(url);
|
|
|
|
// The answer depends on the visitor's language: caches must keep one per language.
|
|
if (decision.negotiated) {
|
|
response.headers.append("Vary", "Accept-Language, Cookie");
|
|
}
|
|
return response;
|
|
}
|
|
|
|
export const config = {
|
|
// Pages only: not Next's own files, the analytics and error proxies, or files.
|
|
matcher: ["/((?!_next/|stats/|errors/|.*\\..*).*)"],
|
|
};
|