1 import axios from 'axios';
2 import React from 'react';
3 import { Button } from 'react-bootstrap';
4 import { withTranslation } from 'react-i18next';
6 import Icon from '../components/common/Icon';
7 import { useUser } from '../hooks/user';
8 import i18n from '../i18n';
10 const setLanguage = (user, language) => {
11 i18n.changeLanguage(language);
13 axios.post('/api/users/set-language', { language });
17 const LanguageSwitcher = () => {
18 const { user } = useUser();
21 className="text-reset"
22 href={`?lng=${i18n.language === 'de' ? 'en' : 'de'}`}
24 setLanguage(user, i18n.language === 'de' ? 'en' : 'de');
27 title={i18n.language === 'de' ? 'Switch to english' : 'Auf deutsch wechseln'}
28 variant="outline-secondary"
32 {i18n.language === 'de' ? 'Deutsch' : 'English'}
36 export default withTranslation()(LanguageSwitcher);