feat: Wabenhain Honig-Shop Anwendung
Vollstaendige Next.js/Prisma-E-Commerce-Anwendung fuer eine Imkerei: Shop, Warenkorb, Stripe-Checkout, Kundenkonto mit 2FA, Admin-Bereich (Produkte, Ernten, Chargen, Bestellungen, Gutscheine, admin-editierbare Website-Inhalte), i18n (DE/EN), Rate-Limiting/CSP/Audit-Log-Haertung, PostgreSQL- und MySQL-Unterstuetzung ueber austauschbare Prisma- Treiber-Adapter, Unit-/Komponenten-/E2E-Tests.
This commit is contained in:
1 parent
5c76fcc266
commit
c7927f2883
240 files changed
+26096
-137
No files matched your search
@@ -0,0 +1,34 @@
|
||||
"use client";
|
||||
|
||||
import { createContext, useContext, type ReactNode } from "react";
|
||||
import type { Locale } from "./config";
|
||||
import type { Dictionary } from "./dictionary-type";
|
||||
import { getDictionary } from "./get-dictionary";
|
||||
|
||||
interface I18nContextValue {
|
||||
locale: Locale;
|
||||
t: Dictionary;
|
||||
}
|
||||
|
||||
const I18nContext = createContext<I18nContextValue | null>(null);
|
||||
|
||||
/**
|
||||
* Stellt Locale + Uebersetzungswoerterbuch fuer Client Components bereit.
|
||||
* Nimmt bewusst nur die Locale (ein String) als Prop entgegen und loest das
|
||||
* Dictionary selbst per getDictionary() auf, statt das fertige Objekt vom
|
||||
* Server-Layout hereinzureichen — Dictionaries enthalten Funktionswerte
|
||||
* (z.B. fuer Pluralformen), und Funktionen lassen sich nicht als Props von
|
||||
* Server an Client Components uebergeben (RSC-Serialisierungsgrenze).
|
||||
* Server Components rufen stattdessen direkt getDictionary(await
|
||||
* getLocale()) auf, ohne diesen Provider zu benoetigen.
|
||||
*/
|
||||
export function I18nProvider({ locale, children }: { locale: Locale; children: ReactNode }) {
|
||||
const dict = getDictionary(locale);
|
||||
return <I18nContext.Provider value={{ locale, t: dict }}>{children}</I18nContext.Provider>;
|
||||
}
|
||||
|
||||
export function useI18n(): I18nContextValue {
|
||||
const ctx = useContext(I18nContext);
|
||||
if (!ctx) throw new Error("useI18n muss innerhalb von <I18nProvider> verwendet werden.");
|
||||
return ctx;
|
||||
}
|
||||
Reference in new issue
Block a user