-
Notifications
You must be signed in to change notification settings - Fork 964
Expand file tree
/
Copy pathLanguageSwitch.js
More file actions
37 lines (32 loc) · 1005 Bytes
/
LanguageSwitch.js
File metadata and controls
37 lines (32 loc) · 1005 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import React from 'react';
import { Dropdown, Icon } from 'semantic-ui-react';
import { useTranslation } from 'react-i18next';
const languages = [
{ key: 'en', text: 'English', value: 'en', flag: 'us' },
{ key: 'zh', text: '中文', value: 'zh', flag: 'cn' },
{ key: 'de', text: 'Deutsch', value: 'de', flag: 'de' },
{ key: 'fr', text: 'Français', value: 'fr', flag: 'fr' }
];
export default function LanguageSwitch() {
const { i18n } = useTranslation();
const handleLanguageChange = (e, { value }) => {
i18n.changeLanguage(value);
};
const currentLanguage = languages.find(lang => lang.value === i18n.language) || languages[0];
return (
<Dropdown
trigger={
<span className="language-switch">
<Icon name="world" />
{currentLanguage.text}
</span>
}
options={languages}
pointing="top right"
icon={null}
value={i18n.language}
onChange={handleLanguageChange}
selectOnBlur={false}
/>
);
}