From 1ff10621f157e881558ad8306aca9fea2878598a Mon Sep 17 00:00:00 2001 From: hailin Date: Thu, 17 Apr 2025 11:33:33 +0800 Subject: [PATCH] . --- components/ui/language-switcher.tsx | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/components/ui/language-switcher.tsx b/components/ui/language-switcher.tsx index 1e302d7..55241b4 100644 --- a/components/ui/language-switcher.tsx +++ b/components/ui/language-switcher.tsx @@ -29,28 +29,28 @@ export function LanguageSwitcher() { const newLocale = e.target.value console.log('[LanguageSwitcher] User selected newLocale:', newLocale) console.log('[LanguageSwitcher] Current pathname:', pathname) - + if (typeof window !== 'undefined') { localStorage.setItem('preferred-language', newLocale) console.log('[LanguageSwitcher] Saved newLocale to localStorage') } - - const segments = pathname.split('/') + + let segments = pathname.split('/').filter(Boolean) console.log('[LanguageSwitcher] Segments before change:', segments) - + const localeList = [...i18nConfig.locales] as string[] - const isLocaleInPath = localeList.includes(segments[1]) + const isLocaleInPath = localeList.includes(segments[0]) console.log('[LanguageSwitcher] isLocaleInPath:', isLocaleInPath) - + if (isLocaleInPath) { - segments[1] = newLocale + segments[0] = newLocale } else { segments.unshift(newLocale) } - - const newPath = segments.join('/') + + const newPath = '/' + segments.join('/') console.log('[LanguageSwitcher] Final newPath:', newPath) - + startTransition(() => { router.push(newPath) router.refresh()