Files
gitlab-instance-0a899031_di…/app/[locale]/layout.tsx
2026-03-08 06:43:48 -05:00

42 lines
1.0 KiB
TypeScript

import type { Metadata } from "next";
import { notFound } from "next/navigation";
import { LocaleProvider } from "../context/LocaleContext";
import type { Locale } from "../context/LocaleContext";
import { getThemeConfig } from "@/config";
import { getThemeMessages } from "@/app/lib/theme-data";
const LOCALES: Locale[] = ["zh", "en"];
export const metadata: Metadata = (() => {
const theme = getThemeConfig();
return {
title: theme.meta.title,
description: theme.meta.description,
};
})();
export function generateStaticParams() {
return LOCALES.map((locale) => ({ locale }));
}
export default async function LocaleLayout({
children,
params,
}: {
children: React.ReactNode;
params: Promise<{ locale: string }>;
}) {
const { locale } = await params;
if (!LOCALES.includes(locale as Locale)) {
notFound();
}
const messages = await getThemeMessages(locale as Locale);
return (
<LocaleProvider locale={locale as Locale} messages={messages}>
{children}
</LocaleProvider>
);
}