fix: setRequestLocale in all server pages, update i18n/request.ts API

This commit is contained in:
Romain bogdanovic 2026-03-28 19:46:46 +01:00
parent 547083ed91
commit bf454b58a3
13 changed files with 29 additions and 15 deletions

View File

@ -1,7 +1,7 @@
import { redirect, notFound } from "next/navigation";
import { auth } from "@/auth";
import { db } from "@/lib/db";
import { getTranslations } from "next-intl/server";
import { getTranslations, setRequestLocale } from "next-intl/server";
import Link from "next/link";
import { CourseForm } from "../CourseForm";
import { ModuleManager } from "./ModuleManager";

View File

@ -1,7 +1,7 @@
export const dynamic = "force-dynamic";
import { redirect } from "next/navigation";
import { auth } from "@/auth";
import { getTranslations } from "next-intl/server";
import { getTranslations, setRequestLocale } from "next-intl/server";
import Link from "next/link";
import { CourseForm } from "../CourseForm";
@ -11,6 +11,7 @@ export default async function NewCoursePage({
params: Promise<{ locale: string }>;
}) {
const { locale } = await params;
setRequestLocale(locale);
const t = await getTranslations({ locale, namespace: "admin" });
const session = await auth();

View File

@ -1,7 +1,7 @@
import { redirect } from "next/navigation";
import { auth } from "@/auth";
import { db } from "@/lib/db";
import { getTranslations } from "next-intl/server";
import { getTranslations, setRequestLocale } from "next-intl/server";
import Link from "next/link";
import { AdminCourseActions } from "./AdminCourseActions";
@ -20,6 +20,7 @@ export default async function AdminCoursesPage({
params: Promise<{ locale: string }>;
}) {
const { locale } = await params;
setRequestLocale(locale);
const t = await getTranslations({ locale, namespace: "admin" });
const session = await auth();

View File

@ -1,7 +1,7 @@
import { redirect } from "next/navigation";
import { auth } from "@/auth";
import { db } from "@/lib/db";
import { getTranslations } from "next-intl/server";
import { getTranslations, setRequestLocale } from "next-intl/server";
import Link from "next/link";
export const dynamic = "force-dynamic";
@ -12,6 +12,7 @@ export default async function AdminDashboardPage({
params: Promise<{ locale: string }>;
}) {
const { locale } = await params;
setRequestLocale(locale);
const t = await getTranslations({ locale, namespace: "admin" });
const session = await auth();

View File

@ -1,7 +1,7 @@
import { redirect } from "next/navigation";
import { auth } from "@/auth";
import { db } from "@/lib/db";
import { getTranslations } from "next-intl/server";
import { getTranslations, setRequestLocale } from "next-intl/server";
import Link from "next/link";
export const dynamic = "force-dynamic";
@ -14,6 +14,7 @@ export default async function AdminStudentsPage({
searchParams: Promise<{ q?: string }>;
}) {
const { locale } = await params;
setRequestLocale(locale);
const { q } = await searchParams;
const t = await getTranslations({ locale, namespace: "admin" });
const session = await auth();

View File

@ -1,5 +1,5 @@
export const dynamic = "force-dynamic";
import { getTranslations } from "next-intl/server";
import { getTranslations, setRequestLocale } from "next-intl/server";
import Link from "next/link";
export default async function VerifyPage({
@ -8,6 +8,7 @@ export default async function VerifyPage({
params: Promise<{ locale: string }>;
}) {
const { locale } = await params;
setRequestLocale(locale);
const t = await getTranslations({ locale, namespace: "auth" });
return (

View File

@ -1,7 +1,7 @@
import { redirect, notFound } from "next/navigation";
import { auth } from "@/auth";
import { db } from "@/lib/db";
import { getTranslations } from "next-intl/server";
import { getTranslations, setRequestLocale } from "next-intl/server";
import Link from "next/link";
import { LessonContent } from "./LessonContent";

View File

@ -1,4 +1,4 @@
import { getTranslations } from "next-intl/server";
import { getTranslations, setRequestLocale } from "next-intl/server";
import { notFound } from "next/navigation";
import Link from "next/link";
import { db } from "@/lib/db";

View File

@ -1,4 +1,4 @@
import { getTranslations } from "next-intl/server";
import { getTranslations, setRequestLocale } from "next-intl/server";
import { db } from "@/lib/db";
import { auth } from "@/auth";
import { CourseCard } from "@/components/CourseCard";
@ -17,6 +17,7 @@ export default async function CoursesPage({
searchParams: Promise<{ category?: string; level?: string; q?: string }>;
}) {
const { locale } = await params;
setRequestLocale(locale);
const { category, level, q } = await searchParams;
const t = await getTranslations({ locale, namespace: "home" });
const courseT = await getTranslations({ locale, namespace: "course" });

View File

@ -1,7 +1,7 @@
import { redirect } from "next/navigation";
import { auth } from "@/auth";
import { db } from "@/lib/db";
import { getTranslations } from "next-intl/server";
import { getTranslations, setRequestLocale } from "next-intl/server";
import Link from "next/link";
import { ProgressBar } from "@/components/ProgressBar";
@ -19,6 +19,7 @@ export default async function DashboardPage({
params: Promise<{ locale: string }>;
}) {
const { locale } = await params;
setRequestLocale(locale);
const t = await getTranslations({ locale, namespace: "dashboard" });
const courseT = await getTranslations({ locale, namespace: "course" });
const session = await auth();

View File

@ -1,5 +1,5 @@
import { NextIntlClientProvider } from "next-intl";
import { getMessages } from "next-intl/server";
import { getMessages, setRequestLocale } from "next-intl/server";
import { notFound } from "next/navigation";
import { auth } from "@/auth";
import { Nav } from "@/components/Nav";
@ -24,6 +24,8 @@ export default async function LocaleLayout({
notFound();
}
setRequestLocale(locale);
const messages = await getMessages();
const session = await auth();
const userRole = (session?.user as any)?.role;

View File

@ -1,5 +1,5 @@
export const dynamic = "force-dynamic";
import { getTranslations } from "next-intl/server";
import { getTranslations, setRequestLocale } from "next-intl/server";
import Link from "next/link";
import { db } from "@/lib/db";
import { CourseCard } from "@/components/CourseCard";
@ -11,6 +11,7 @@ export default async function HomePage({
params: Promise<{ locale: string }>;
}) {
const { locale } = await params;
setRequestLocale(locale);
const t = await getTranslations({ locale, namespace: "home" });
const nav = await getTranslations({ locale, namespace: "nav" });
const courseT = await getTranslations({ locale, namespace: "course" });

View File

@ -1,5 +1,9 @@
import { getRequestConfig } from "next-intl/server";
export default getRequestConfig(async ({ locale }) => ({
messages: (await import(`../../messages/${locale}.json`)).default,
}));
export default getRequestConfig(async ({ requestLocale }) => {
const locale = (await requestLocale) ?? "fr";
return {
locale,
messages: (await import(`../../messages/${locale}.json`)).default,
};
});