|
|
@@ -1,22 +1,35 @@
|
|
|
-import { Select } from 'antd';
|
|
|
-import { useTranslation } from 'react-i18next';
|
|
|
+import { Dropdown, type MenuProps } from 'antd'
|
|
|
+import { useTranslation } from 'react-i18next'
|
|
|
|
|
|
-const { Option } = Select;
|
|
|
+const LANGUAGES = [
|
|
|
+ { code: 'en-US', label: 'English' },
|
|
|
+ { code: 'zh-CN', label: '简体中文' },
|
|
|
+ { code: 'fa-IR', label: 'فارسی' },
|
|
|
+]
|
|
|
|
|
|
-const LanguageSwitch = () => {
|
|
|
- const { i18n } = useTranslation();
|
|
|
+interface LanguageSwitchProps {
|
|
|
+ className?: string
|
|
|
+}
|
|
|
|
|
|
- const handleChange = (value: string) => {
|
|
|
- i18n.changeLanguage(value);
|
|
|
- };
|
|
|
+export function LanguageSwitch({ className }: LanguageSwitchProps) {
|
|
|
+ const { i18n, t } = useTranslation()
|
|
|
+
|
|
|
+ const menuProps: MenuProps = {
|
|
|
+ items: LANGUAGES.map((lang) => ({
|
|
|
+ key: lang.code,
|
|
|
+ label: lang.label,
|
|
|
+ })),
|
|
|
+ selectedKeys: [i18n.language],
|
|
|
+ onClick: ({ key }) => i18n.changeLanguage(key),
|
|
|
+ }
|
|
|
|
|
|
return (
|
|
|
- <Select value={i18n.language} onChange={handleChange} style={{ width: 120 }}>
|
|
|
- <Option value="fa-IR">فارسی</Option>
|
|
|
- <Option value="en-US">English</Option>
|
|
|
- <Option value="zh-CN">简体中文</Option>
|
|
|
- </Select>
|
|
|
- );
|
|
|
-};
|
|
|
+ <Dropdown menu={menuProps} trigger={['click']} placement="bottomRight">
|
|
|
+ <button type="button" className={className}>
|
|
|
+ {t('components.topbar.language')}
|
|
|
+ </button>
|
|
|
+ </Dropdown>
|
|
|
+ )
|
|
|
+}
|
|
|
|
|
|
-export default LanguageSwitch;
|
|
|
+export default LanguageSwitch
|