fix: hydration on i18n
This commit is contained in:
@@ -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}</>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user