diff --git a/src/app/[locale]/layout.tsx b/src/app/[locale]/layout.tsx index 1c0d4ef..00a7336 100644 --- a/src/app/[locale]/layout.tsx +++ b/src/app/[locale]/layout.tsx @@ -1,5 +1,9 @@ import type { Metadata } from "next"; import { Inter } from "next/font/google"; +import { unstable_setRequestLocale } from "next-intl/server"; + +import { locales } from "@/i18n"; + import "./globals.css"; const inter = Inter({ subsets: ["latin"] }); @@ -9,6 +13,10 @@ export const metadata: Metadata = { description: "Generated by create next app", }; +export function generateStaticParams() { + return locales.map((locale) => ({ locale })); +} + type LayoutProps = { children: React.ReactNode; params: { @@ -20,6 +28,10 @@ export default function RootLayout({ children, params: { locale }, }: LayoutProps) { + // Cache the request locale using a temporary API, to make it available to downstream components. + // See https://next-intl-docs.vercel.app/docs/getting-started/app-router#add-unstable_setrequestlocale-to-all-layouts-and-pages for more details. + unstable_setRequestLocale(locale); + return ( {children} diff --git a/src/navigation.ts b/src/navigation.ts new file mode 100644 index 0000000..f9ca657 --- /dev/null +++ b/src/navigation.ts @@ -0,0 +1,5 @@ +import { createSharedPathnamesNavigation } from "next-intl/navigation"; +import { locales } from "./i18n"; + +export const { Link, redirect, usePathname, useRouter } = + createSharedPathnamesNavigation({ locales });