i10n using NextIntl

This commit is contained in:
Dobromir Popov
2024-04-28 22:56:41 +03:00
parent 46df4b6066
commit 6d2885de59
12 changed files with 304 additions and 11 deletions

View File

@ -0,0 +1,24 @@
import { useRouter } from 'next/router';
import { useTranslations } from 'next-intl';
// using https://next-intl-docs.vercel.app/docs/getting-started/pages-router
const LanguageSwitcher = () => {
const t = useTranslations('common');
const router = useRouter();
const { locale, locales, asPath } = router;
return (
<div>
{locales.map((lng) => {
if (lng === locale) return null;
return (
<button key={lng} onClick={() => router.push(asPath, asPath, { locale: lng })}>
{t('changeTo')} {t(lng.toUpperCase())}
</button>
);
})}
</div>
);
};
export default LanguageSwitcher;