diff --git a/src/app/[locale]/layout.tsx b/src/app/[locale]/layout.tsx new file mode 100644 index 0000000..1430e59 --- /dev/null +++ b/src/app/[locale]/layout.tsx @@ -0,0 +1,26 @@ +import { setRequestLocale } from 'next-intl/server'; +import { hasLocale } from 'next-intl'; +import { notFound } from 'next/navigation'; +import { routing } from '@/i18n/routing'; + +export function generateStaticParams() { + return routing.locales.map((locale) => ({ locale })); +} + +export default async function LocaleLayout({ + children, + params, +}: { + children: React.ReactNode; + params: Promise<{ locale: string }>; +}) { + const { locale } = await params; + + if (!hasLocale(routing.locales, locale)) { + notFound(); + } + + setRequestLocale(locale); + + return <>{children}; +} diff --git a/src/app/layout.tsx b/src/app/layout.tsx index 8e51c13..e32c57e 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -1,4 +1,5 @@ import type { Metadata } from 'next'; +import { headers } from 'next/headers'; import './globals.css'; import { NextIntlClientProvider } from 'next-intl'; import { ThemeProvider } from '@wrksz/themes/next'; @@ -14,14 +15,17 @@ export const metadata: Metadata = { description: 'Create SaaS in a day!', }; -export default function RootLayout({ +export default async function RootLayout({ children, }: Readonly<{ children: React.ReactNode; }>) { + const headersList = await headers(); + const locale = headersList.get('x-next-intl-locale') || 'en'; + return (