fix: hydration on i18n

This commit is contained in:
Julien Froidefond
2025-02-27 11:41:35 +01:00
parent f39e4779cf
commit c56a22b5dc
3 changed files with 50 additions and 4 deletions

View File

@@ -1,8 +1,26 @@
"use client";
import { PropsWithChildren, useEffect } from "react";
import { PropsWithChildren } from "react";
import { useTranslate } from "@/hooks/useTranslate";
import "@/i18n/i18n";
export function I18nProvider({ children }: PropsWithChildren) {
export function I18nProvider({ children, locale }: PropsWithChildren<{ locale: string }>) {
const { i18n } = useTranslate();
// Synchroniser la langue avec celle du cookie côté client
if (typeof window !== "undefined") {
const localeCookie = document.cookie.split("; ").find((row) => row.startsWith("NEXT_LOCALE="));
console.log(localeCookie);
if (localeCookie) {
const locale = localeCookie.split("=")[1];
if (i18n.language !== locale) {
i18n.changeLanguage(locale);
}
}
} else {
if (i18n.language !== locale) {
i18n.changeLanguage(locale);
}
}
return <>{children}</>;
}