a550d6d0fd
- Next.js + MapLibre GL 3D 地球 - CARTO dark-matter vector 底图 - 动态星空背景(闪烁、漂移、流星) - 经纬网格线(graticule) - 文物数据图层与朝代/类别筛选 - 中国风信息弹窗 - 中英双语 i18n - LayerPanel + MapControls 浮动面板
29 lines
884 B
TypeScript
29 lines
884 B
TypeScript
'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 (
|
|
<button
|
|
onClick={toggleLanguage}
|
|
className="flex items-center gap-1.5 px-2.5 py-1.5 rounded-md text-sm font-medium text-[var(--map-text-muted)] hover:text-white hover:bg-white/10 transition-colors"
|
|
aria-label="Switch language"
|
|
>
|
|
<Globe className="w-4 h-4" />
|
|
<span>{locale === 'zh' ? 'EN' : '中文'}</span>
|
|
</button>
|
|
);
|
|
} |