中英文切换 初始化

This commit is contained in:
mmc
2026-08-12 11:29:44 +08:00
parent 541e16f742
commit a8af55a856
76 changed files with 5847 additions and 1962 deletions

View File

@@ -0,0 +1,46 @@
import React from 'react';
import { Button, Dropdown } from 'antd';
import { GlobalOutlined } from '@ant-design/icons';
import { useTranslation } from 'react-i18next';
import type { MenuProps } from 'antd';
export default function LanguageSwitcher() {
const { i18n } = useTranslation();
const currentLng = i18n.language?.startsWith('en') ? 'en' : 'zh';
const items: MenuProps['items'] = [
{
key: 'zh',
label: (
<span style={{ fontWeight: currentLng === 'zh' ? 600 : 400 }}>
中文
</span>
),
},
{
key: 'en',
label: (
<span style={{ fontWeight: currentLng === 'en' ? 600 : 400 }}>
English
</span>
),
},
];
const handleChange: MenuProps['onClick'] = ({ key }) => {
i18n.changeLanguage(key);
localStorage.setItem('i18nextLng', key);
};
return (
<Dropdown menu={{ items, onClick: handleChange }} placement="bottomRight">
<Button
type="text"
icon={<GlobalOutlined />}
style={{ color: '#fff', fontSize: 'clamp(12px, 1vw, 14px)' }}
>
{currentLng === 'zh' ? '中文' : 'EN'}
</Button>
</Dropdown>
);
}