'use client' /** * LanguageSwitcher - 賽博風語系切換器 * * Nothing.tech 風格極簡設計 * 支援 EN / 繁中 切換 */ import { useLocale } from 'next-intl' import { useRouter, usePathname, locales, localeShortNames, type Locale } from '@/i18n/routing' import { cn } from '@/lib/utils' interface LanguageSwitcherProps { className?: string } export function LanguageSwitcher({ className }: LanguageSwitcherProps) { const locale = useLocale() as Locale const router = useRouter() const pathname = usePathname() const handleSwitch = (newLocale: Locale) => { if (newLocale === locale) return router.replace(pathname, { locale: newLocale }) } return (
{locales.map((loc) => { const isActive = loc === locale return ( ) })}
) } /** * LanguageSwitcherCompact - 更緊湊的版本 * 只顯示當前語系,點擊切換 */ export function LanguageSwitcherCompact({ className }: LanguageSwitcherProps) { const locale = useLocale() as Locale const router = useRouter() const pathname = usePathname() const handleToggle = () => { const currentIndex = locales.indexOf(locale) const nextIndex = (currentIndex + 1) % locales.length const newLocale = locales[nextIndex] router.replace(pathname, { locale: newLocale }) } return ( ) }