Files
umami/src/app/Providers.tsx
T
Mike CaoandClaude Opus 4.6 a1890e9261 Replace react-intl with next-intl and consolidate lang files.
Migrate i18n from react-intl to next-intl, eliminating the formatjs
compilation pipeline. Translation files now live as nested JSON in
public/intl/messages/ (single source of truth), removing the duplicated
src/lang/ directory and the copy/compile build steps. The useMessages()
hook API is preserved so all 195+ consumer components are unchanged.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-07 01:51:29 -08:00

63 lines
1.6 KiB
TypeScript

'use client';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { RouterProvider, ZenProvider } from '@umami/react-zen';
import { useRouter } from 'next/navigation';
import { NextIntlClientProvider } from 'next-intl';
import { useEffect } from 'react';
import { ErrorBoundary } from '@/components/common/ErrorBoundary';
import { useLocale } from '@/components/hooks';
import 'chartjs-adapter-date-fns';
const client = new QueryClient({
defaultOptions: {
queries: {
retry: false,
refetchOnWindowFocus: false,
staleTime: 1000 * 60,
},
},
});
function MessagesProvider({ children }) {
const { locale, messages, dir } = useLocale();
useEffect(() => {
document.documentElement.setAttribute('dir', dir);
document.documentElement.setAttribute('lang', locale);
}, [locale, dir]);
return (
<NextIntlClientProvider locale={locale} messages={messages[locale]} onError={() => null}>
{children}
</NextIntlClientProvider>
);
}
export function Providers({ children }) {
const router = useRouter();
function navigate(url: string) {
if (shouldUseNativeLink(url)) {
window.location.href = url;
} else {
router.push(url);
}
}
function shouldUseNativeLink(url: string) {
return url.startsWith('http');
}
return (
<ZenProvider>
<RouterProvider navigate={navigate}>
<MessagesProvider>
<QueryClientProvider client={client}>
<ErrorBoundary>{children}</ErrorBoundary>
</QueryClientProvider>
</MessagesProvider>
</RouterProvider>
</ZenProvider>
);
}