Added dropdown for easy locale switching.

dependabot/npm_and_yarn/typescript-eslint/parser-4.33.0
Guusvanmeerveld 3 years ago
parent cf4d66b61a
commit 07e8106807

@ -1,6 +1,6 @@
import { useI18n } from 'next-localization';
import { useRouter } from 'next/router';
import { useTheme } from 'next-themes';
import { GetStaticProps } from 'next';
import Link from 'next/link';
import { BiMoon } from 'react-icons/bi';
@ -10,6 +10,28 @@ import { FC } from 'react';
import styles from './Navbar.module.scss';
const LanguageSelector: FC = () => {
const router = useRouter();
const path = router.pathname;
return (
<select className={styles.select} defaultValue={router.locale}>
{router.locales.map((locale) => (
<option
key={locale}
onClick={() => {
router.push(path, path, { locale });
}}
value={locale}
>
{locale.toUpperCase()}
</option>
))}
</select>
);
};
const Navbar: FC = () => {
const { t } = useI18n();
@ -35,10 +57,7 @@ const Navbar: FC = () => {
<BiMoon onClick={switchTheme} className={styles.moon} />
<ImSun onClick={switchTheme} className={styles.sun} />
<select className={styles.select}>
<option value="nl">NL</option>
<option value="en">EN</option>
</select>
<LanguageSelector />
</div>
</div>
</div>
@ -46,12 +65,4 @@ const Navbar: FC = () => {
);
};
export const getStaticProps: GetStaticProps = async ({ locale }) => {
const { default: lngDict = {} } = await import(`../locales/${locale}.json`);
return {
props: { lngDict },
};
};
export default Navbar;

@ -0,0 +1,9 @@
import { GetStaticProps } from 'next';
export const getStaticProps: GetStaticProps = async ({ locale }) => {
const { default: lngDict = {} } = await import(`./locales/${locale}.json`);
return {
props: { lngDict },
};
};

@ -4,6 +4,8 @@ import Page from '@components/Page';
import Layout from '@components/Layout';
import PageBuilder from '@components/PageBuilder';
export { getStaticProps } from '../locales';
const NotFound: FC = () => (
<Page title="Page not found" description="This page either doesn't exist or has been deleted">
<Layout>

@ -6,6 +6,8 @@ import ReCAPTCHA from 'react-google-recaptcha';
import Page from '@components/Page';
import Layout from '@components/Layout';
export { getStaticProps } from '../locales';
import styles from './contact.module.scss';
const formURL = 'https://forms.guusvanmeerveld.dev/portfolio';

@ -14,6 +14,8 @@ import Page from '@components/Page';
import Shift from '@models/shifts';
export { getStaticProps } from '../locales';
import styles from './shifts.module.scss';
interface APIResponse {

@ -4,6 +4,8 @@ import Page from '@components/Page';
import Layout from '@components/Layout';
import PageBuilder from '@components/PageBuilder';
export { getStaticProps } from '../locales';
import styles from './thanks.module.scss';
const Thanks: NextPage = () => (

Loading…
Cancel
Save