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()