Files
homaroma/apps/website/src/components/ClientProviders.tsx
T
2026-06-20 18:39:03 -04:00

28 lines
796 B
TypeScript

"use client";
import '../lib/i18n';
import CartDrawer from './CartDrawer';
import ScrollToTop from './ScrollToTop';
import { useEffect, type ReactNode } from 'react';
import i18n from '../lib/i18n';
export default function ClientProviders({ children }: { children: ReactNode }) {
useEffect(() => {
// With Locale Routing, the URL is the source of truth for language.
// Sync i18n to match the current URL if needed.
const pathLang = window.location.pathname.split('/')[1];
const targetLang = pathLang && ['th', 'en', 'ja', 'zh', 'vi', 'ko'].includes(pathLang) ? pathLang : 'th';
if (targetLang !== i18n.language) {
void i18n.changeLanguage(targetLang);
}
}, [])
return (
<>
<ScrollToTop />
{children}
<CartDrawer />
</>
);
}