diff --git a/client/components/build/RightSidebar/sections/Settings.tsx b/client/components/build/RightSidebar/sections/Settings.tsx index 55d8256f..9d59cdf3 100644 --- a/client/components/build/RightSidebar/sections/Settings.tsx +++ b/client/components/build/RightSidebar/sections/Settings.tsx @@ -63,13 +63,13 @@ const Settings = () => { const handleChangeLanguage = (value: Language | null) => { const { pathname, asPath, query } = router; - const locale = value?.code || 'en'; + const code = value?.code || 'en'; - dayjs.locale(locale); - dispatch(setLanguage({ language: locale || 'en' })); - document.cookie = `NEXT_LOCALE=${locale}; path=/; expires=2147483647`; + dayjs.locale(code); + dispatch(setLanguage({ language: code })); + document.cookie = `NEXT_LOCALE=${code}; path=/; expires=2147483647`; - router.push({ pathname, query }, asPath, { locale }); + router.push({ pathname, query }, asPath, { locale: code }); }; const handleLoadSampleData = async () => { diff --git a/client/components/shared/Footer.tsx b/client/components/shared/Footer.tsx index 76d80a89..1bd8f2f6 100644 --- a/client/components/shared/Footer.tsx +++ b/client/components/shared/Footer.tsx @@ -9,7 +9,7 @@ const Footer: React.FC = ({ className }) => { const { t } = useTranslation(); return ( - + ); }; diff --git a/client/components/shared/LanguageSwitcher.module.scss b/client/components/shared/LanguageSwitcher.module.scss new file mode 100644 index 00000000..f34d2d2c --- /dev/null +++ b/client/components/shared/LanguageSwitcher.module.scss @@ -0,0 +1,13 @@ +.popover { + width: 460px; + + @apply px-4 py-2; +} + +.container { + @apply grid grid-cols-3 items-center justify-center gap-x-2; +} + +.language { + @apply py-2 px-4 cursor-pointer text-center hover:underline; +} diff --git a/client/components/shared/LanguageSwitcher.tsx b/client/components/shared/LanguageSwitcher.tsx new file mode 100644 index 00000000..711832b6 --- /dev/null +++ b/client/components/shared/LanguageSwitcher.tsx @@ -0,0 +1,71 @@ +import { Language } from '@mui/icons-material'; +import { IconButton, Popover } from '@mui/material'; +import dayjs from 'dayjs'; +import { useRouter } from 'next/router'; +import { MouseEvent, useState } from 'react'; + +import { languages } from '@/config/languages'; +import { setLanguage } from '@/store/build/buildSlice'; +import { useAppDispatch } from '@/store/hooks'; + +import styles from './LanguageSwitcher.module.scss'; + +const LanguageSwitcher = () => { + const router = useRouter(); + + const dispatch = useAppDispatch(); + + const [anchorEl, setAnchorEl] = useState(null); + + const handleClick = (event: MouseEvent) => setAnchorEl(event.currentTarget); + + const handleClose = () => setAnchorEl(null); + + const handleChangeLanguage = (locale: string) => { + const { pathname, asPath, query } = router; + + dayjs.locale(locale); + dispatch(setLanguage({ language: locale })); + document.cookie = `NEXT_LOCALE=${locale}; path=/; expires=2147483647`; + + router.push({ pathname, query }, asPath, { locale }); + }; + + return ( +
+ + + + + +
+
+ {languages.map(({ code, name, localName }) => ( +

handleChangeLanguage(code)}> + {name} {localName && `(${localName})`} +

+ ))} + + + Missing your language? + +
+
+
+
+ ); +}; + +export default LanguageSwitcher; diff --git a/client/pages/index.tsx b/client/pages/index.tsx index a61256a1..45747181 100644 --- a/client/pages/index.tsx +++ b/client/pages/index.tsx @@ -9,6 +9,7 @@ import { serverSideTranslations } from 'next-i18next/serverSideTranslations'; import Testimony from '@/components/landing/Testimony'; import Footer from '@/components/shared/Footer'; +import LanguageSwitcher from '@/components/shared/LanguageSwitcher'; import Logo from '@/components/shared/Logo'; import NoSSR from '@/components/shared/NoSSR'; import { screenshots } from '@/config/screenshots'; @@ -180,9 +181,13 @@ const Home: NextPage = () => {