Files
stripstream/src/components/providers/I18nProvider.tsx
Julien Froidefond a4b521fe2e fix: lint type import
2025-03-02 14:02:23 +01:00

27 lines
752 B
TypeScript

"use client";
import type { PropsWithChildren } from "react";
import { useTranslate } from "@/hooks/useTranslate";
import "@/i18n/i18n";
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="));
if (localeCookie) {
const locale = localeCookie.split("=")[1];
if (i18n.language !== locale) {
i18n.changeLanguage(locale);
}
}
} else {
if (i18n.language !== locale) {
i18n.changeLanguage(locale);
}
}
return <>{children}</>;
}