x
This commit is contained in:
1 parent
cfd642dee0
commit
ae3799d8ce
21 files changed
+172
-30
No files matched your search
@@ -7,13 +7,14 @@ import i18n from '../lib/i18n';
|
||||
import { useCartStore } from '../store/cartStore';
|
||||
import { useWishlistStore } from '../store/wishlistStore';
|
||||
import { useAuthStore } from '../store/authStore';
|
||||
import { DEFAULT_LOCALE, SUPPORTED_LOCALES } from '../lib/locales';
|
||||
|
||||
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';
|
||||
const targetLang = pathLang && (SUPPORTED_LOCALES as readonly string[]).includes(pathLang) ? pathLang : DEFAULT_LOCALE;
|
||||
|
||||
if (targetLang !== i18n.language) {
|
||||
void i18n.changeLanguage(targetLang);
|
||||
|
||||
Reference in new issue
Block a user