import { Fragment } from 'react' import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' import { Menu, Transition } from '@headlessui/react' import { useRouter } from 'next/router' import Link from 'next/link' import { useCookies, withCookies } from 'react-cookie' // https://headlessui.dev/react/menu#integrating-with-next-js const CustomLink = ({ href, children, as, locale, ...props }): JSX.Element => { return ( {children} ) } const localeText = (locale: string): string => { switch (locale) { case 'de-DE': return '🇩🇪 Deutsch' case 'en': return '🇬🇧 English' case 'es': return '🇪🇸 Español' case 'zh-CN': return '🇨🇳 简体中文' case 'hi': return '🇮🇳 हिन्दी' case 'id': return '🇮🇩 Indonesia' case 'tr-TR': return '🇹🇷 Türkçe' case 'zh-TW': return '🇹🇼 繁體中文' default: return '🇬🇧 English' } } const SwitchLang = () => { const { locales, pathname, query, asPath } = useRouter() const [_, setCookie] = useCookies(['NEXT_LOCALE']) return (
{locales!.map(locale => ( setCookie('NEXT_LOCALE', locale, { path: '/' })} >
{localeText(locale)}
))}
) } export default withCookies(SwitchLang)