Files
portfolio/components/I18nWrapper.tsx
2026-01-22 20:56:35 +01:00

60 lines
1.3 KiB
TypeScript

/**
* Server Component für i18n-Texte
* Nutzt Directus mit Fallback auf next-intl/JSON
*/
import { getLocalizedMessage, getLocalizedContent } from '@/lib/i18n-loader';
interface I18nTextProps {
msgKey: string;
locale: 'en' | 'de';
fallback?: string; // Falls Key nicht in Directus AND nicht in JSON
}
/**
* Zeigt einen kurzen, lokalisierten Text.
* Directus > next-intl/JSON > Fallback > Key selbst.
*/
export async function I18nText({
msgKey,
locale,
fallback,
}: I18nTextProps) {
const text = await getLocalizedMessage(msgKey, locale);
return <>{text || fallback || msgKey}</>;
}
interface I18nContentProps {
slug: string;
locale: 'en' | 'de';
fallback?: React.ReactNode;
}
/**
* Zeigt ein längeres, lokalisiertes Inhaltsblöck.
* Nur Directus, kein JSON-Fallback.
*/
export async function I18nContent({
slug,
locale,
fallback,
}: I18nContentProps) {
const page = await getLocalizedContent(slug, locale);
if (!page?.content) {
return <>{fallback || null}</>;
}
// Wenn content ein String ist (Markdown/Plain Text):
if (typeof page.content === 'string') {
return <div className="prose prose-stone max-w-none">{page.content}</div>;
}
// Wenn content ein JSON-Objekt ist (Rich Text Editor):
return (
<div className="prose prose-stone max-w-none">
{JSON.stringify(page.content)}
</div>
);
}