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>
35 lines
1.1 KiB
TypeScript
35 lines
1.1 KiB
TypeScript
"use client";
|
|
|
|
import * as React from "react";
|
|
import type { Content } from "@/src/content/types";
|
|
import type { Locale } from "@/src/domain/locale";
|
|
|
|
type Value = { readonly locale: Locale; readonly content: Content };
|
|
|
|
const ContentContext = React.createContext<Value | null>(null);
|
|
|
|
/**
|
|
* ContentProvider: hands the language of the page and its texts to the client
|
|
* components. The layout picks both; only the texts of that one language are
|
|
* sent to the browser.
|
|
*/
|
|
export const ContentProvider: React.FC<
|
|
Value & { children: React.ReactNode }
|
|
> = ({ locale, content, children }) => {
|
|
const value = React.useMemo(() => ({ locale, content }), [locale, content]);
|
|
return (
|
|
<ContentContext.Provider value={value}>{children}</ContentContext.Provider>
|
|
);
|
|
};
|
|
|
|
const useValue = (): Value => {
|
|
const value = React.useContext(ContentContext);
|
|
if (value === null) {
|
|
throw new Error("useContent and useLocale need a ContentProvider above.");
|
|
}
|
|
return value;
|
|
};
|
|
|
|
export const useContent = (): Content => useValue().content;
|
|
export const useLocale = (): Locale => useValue().locale;
|