'use client'; import { useLocale } from 'next-intl'; import { useRouter, usePathname } from 'next/navigation'; import { Globe } from 'lucide-react'; export function LanguageSwitcher() { const locale = useLocale(); const router = useRouter(); const pathname = usePathname(); const toggleLanguage = () => { const newLocale = locale === 'zh' ? 'en' : 'zh'; // 替换 URL 中的语言前缀 const newPath = pathname.replace(`/${locale}`, `/${newLocale}`); router.push(newPath); }; return ( ); }