diff --git a/components/languageSwitcher.tsx b/components/languageSwitcher.tsx index e4c2663..4131523 100644 --- a/components/languageSwitcher.tsx +++ b/components/languageSwitcher.tsx @@ -1,4 +1,9 @@ +import { useState } from 'react'; import { useRouter } from 'next/router'; +import Menu from '@mui/material/Menu'; +import MenuItem from '@mui/material/MenuItem'; +import IconButton from '@mui/material/IconButton'; +import TranslateIcon from '@mui/icons-material/Translate'; import { useTranslations } from 'next-intl'; // using https://next-intl-docs.vercel.app/docs/getting-started/pages-router @@ -7,18 +12,44 @@ const LanguageSwitcher = () => { const router = useRouter(); const { locale, locales, asPath } = router; + const [anchorEl, setAnchorEl] = useState(null); + + const handleClick = (event) => { + setAnchorEl(event.currentTarget); + }; + + const handleClose = () => { + setAnchorEl(null); + }; + + const changeLanguage = (lng) => { + router.push(asPath, asPath, { locale: lng }); + handleClose(); + }; + return (
- {locales.map((lng) => { - if (lng === locale) return null; - return ( - - ); - })} + + + + + {locales.map((lng) => { + if (lng === locale) return null; + return ( + changeLanguage(lng)}> + {t('changeTo')} {t(lng.toUpperCase())} + + ); + })} +
); }; -export default LanguageSwitcher; \ No newline at end of file +export default LanguageSwitcher;