import { getLocale, setLocale } from '@umijs/max'; import { useEffect, useState } from 'react'; const LangSwitches = () => { const [isEnglish, setIsEnglish] = useState(false); // Keep checkbox in sync with current Umi locale without forcing a reload useEffect(() => { const syncLocale = () => setIsEnglish(getLocale() === 'en-US'); syncLocale(); window.addEventListener('languagechange', syncLocale); return () => { window.removeEventListener('languagechange', syncLocale); }; }, []); const handleLanguageChange = (e: React.ChangeEvent) => { const newLocale = e.target.checked ? 'en-US' : 'vi-VN'; setIsEnglish(e.target.checked); setLocale(newLocale, false); // Update locale instantly without full page reload }; return ( ); }; export default LangSwitches;