auto translation setup

This commit is contained in:
2026-04-17 10:46:24 +02:00
parent e1efa898b4
commit dbeb294920
3 changed files with 46 additions and 19 deletions
+13 -4
View File
@@ -1,5 +1,7 @@
import type { Metadata } from "next"; import type { Metadata } from "next";
import { Playfair_Display, Inter } from "next/font/google"; import { Playfair_Display, Inter } from "next/font/google";
import { NextIntlClientProvider } from "next-intl";
import { getMessages } from 'next-intl/server';
import "./globals.css"; import "./globals.css";
@@ -22,15 +24,21 @@ export const metadata: Metadata = {
description: "Portfolio de Mathéo Guilbert, développeur web freelance.", description: "Portfolio de Mathéo Guilbert, développeur web freelance.",
}; };
export default function RootLayout({ export default async function RootLayout({
children, children,
}: Readonly<{ params,
}: {
children: React.ReactNode; children: React.ReactNode;
}>) { params: Promise<{ locale: string }>;
}) {
const { locale } = await params;
const messages = await getMessages();
return ( return (
<html lang="fr" className={`${playfairDisplay.variable} ${inter.variable} bg-brand-beige overflow-hidden antialiased`}> <html lang={locale} className={`${playfairDisplay.variable} ${inter.variable} bg-brand-beige overflow-hidden antialiased`}>
<body className="h-screen w-screen bg-brand-beige text-brand-brown flex flex-col overflow-hidden"> <body className="h-screen w-screen bg-brand-beige text-brand-brown flex flex-col overflow-hidden">
<NextIntlClientProvider messages={messages}>
<div className="sticky top-0 z-50 bg-brand-beige w-full px-2.75 pt-2.75"> <div className="sticky top-0 z-50 bg-brand-beige w-full px-2.75 pt-2.75">
<Header /> <Header />
</div> </div>
@@ -43,6 +51,7 @@ export default function RootLayout({
<Footer /> <Footer />
</CustomScrollArea> </CustomScrollArea>
</NextIntlClientProvider>
</body> </body>
</html> </html>
); );
+15
View File
@@ -0,0 +1,15 @@
import { getRequestConfig } from 'next-intl/server';
import { notFound } from 'next/navigation';
const locales = ['fr', 'en'];
export default getRequestConfig(async ({ requestLocale }) => {
const locale = await requestLocale;
if (!locale || !locales.includes(locale)) notFound();
return {
locale,
messages: (await import(`./messages/${locale}.json`)).default
};
});
+4 -1
View File
@@ -1,7 +1,10 @@
import type { NextConfig } from "next"; import type { NextConfig } from "next";
import createNextIntlPlugin from 'next-intl/plugin';
const nextConfig: NextConfig = { const nextConfig: NextConfig = {
/* config options here */ /* config options here */
}; };
export default nextConfig; const withNextIntl = createNextIntlPlugin('./i18n.ts');
export default withNextIntl(nextConfig);