"use client"; import { type Messages, setupI18n } from "@lingui/core"; import { I18nProvider } from "@lingui/react"; import { type ReactNode, useEffect, useMemo } from "react"; import { DEFAULT_LOCALE, type Locale } from "@/utils/i18n/locales"; export function LinguiClientProvider({ locale, messages, children, }: { locale: Locale; messages: Messages; children: ReactNode; }) { // Rebuilt only when the locale changes. Every server re-render of the layout // (refreshes, revalidated actions) sends a new copy of the same catalog, and a // new instance would change `t` and re-run every effect that depends on it. // biome-ignore lint/correctness/useExhaustiveDependencies: a locale's catalog never changes at runtime const i18n = useMemo( () => setupI18n({ locale, messages: { [locale]: messages } }), [locale], ); // Localized landing URLs set lang in the root layout. This still updates it // on client navigations and for the app locale cookie, and restores English // when the provider unmounts. useEffect(() => { document.documentElement.lang = locale; return () => { document.documentElement.lang = DEFAULT_LOCALE; }; }, [locale]); return {children}; }