i18n-Fundament: Cookie-basierte Sprachumschaltung (DE/EN/PL)
Wörterbücher unter lib/i18n statt next-intl (Next.js 16 ist neu genug, dass eine externe Routing-Middleware zusätzliches Risiko bedeutet hätte); Sprache liegt in einem Cookie, kein URL-Präfix nötig, dadurch bleibt proxy.ts unverändert. LocaleProvider stellt Wörterbuch + Sprache per Context für Client-Komponenten bereit (lib/i18n/shared.ts ist bewusst getrennt von lib/i18n/index.ts, damit next/headers nicht in den Client-Bundle gelangt).
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
// Nur für Server-Komponenten/Routen importieren (next/headers)!
|
||||
// Client-Komponenten müssen stattdessen "@/lib/i18n/shared" verwenden,
|
||||
// sonst landet next/headers im Client-Bundle.
|
||||
|
||||
import "server-only";
|
||||
import { cookies } from "next/headers";
|
||||
import { DEFAULT_LOCALE, isLocale, type Locale } from "./locales";
|
||||
|
||||
export * from "./shared";
|
||||
|
||||
/** Aktuelle Sprache aus dem Cookie lesen (Server-Komponenten). */
|
||||
export async function getLocale(): Promise<Locale> {
|
||||
const store = await cookies();
|
||||
const value = store.get("locale")?.value;
|
||||
return isLocale(value) ? value : DEFAULT_LOCALE;
|
||||
}
|
||||
Reference in New Issue
Block a user