Skip to content

Commit

Permalink
fix(i18n): fix language mismatch in exported pdf
Browse files Browse the repository at this point in the history
  • Loading branch information
AmruthPillai committed May 24, 2022
1 parent ee5b018 commit 62fd63e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
8 changes: 8 additions & 0 deletions client/pages/[username]/[slug]/index.tsx
Expand Up @@ -59,6 +59,14 @@ const Preview: NextPage<Props> = ({ username, slug, resume: initialData }) => {
}
}, [dispatch, initialData]);

useEffect(() => {
if (!isEmpty(resume) && router.locale !== resume.metadata.locale) {
const { pathname, asPath, query } = router;

router.push({ pathname, query }, asPath, { locale: resume.metadata.locale });
}
}, [resume, router]);

useQuery<Resume>(`resume/${username}/${slug}`, () => fetchResumeByIdentifier({ username, slug }), {
initialData,
retry: false,
Expand Down
11 changes: 11 additions & 0 deletions client/pages/r/[shortId].tsx
Expand Up @@ -7,6 +7,7 @@ import get from 'lodash/get';
import isEmpty from 'lodash/isEmpty';
import { GetServerSideProps, NextPage } from 'next';
import Link from 'next/link';
import { useRouter } from 'next/router';
import { serverSideTranslations } from 'next-i18next/serverSideTranslations';
import { useEffect } from 'react';
import toast from 'react-hot-toast';
Expand Down Expand Up @@ -35,6 +36,8 @@ export const getServerSideProps: GetServerSideProps<Props> = async ({ query, loc
};

const Preview: NextPage<Props> = ({ shortId }) => {
const router = useRouter();

const dispatch = useAppDispatch();

const { data: resume } = useQuery<Resume>(`resume/${shortId}`, () => fetchResumeByShortId({ shortId }), {
Expand All @@ -52,6 +55,14 @@ const Preview: NextPage<Props> = ({ shortId }) => {
if (resume) dispatch(setResume(resume));
}, [resume, dispatch]);

useEffect(() => {
if (resume && !isEmpty(resume) && router.locale !== resume.metadata.locale) {
const { pathname, asPath, query } = router;

router.push({ pathname, query }, asPath, { locale: resume.metadata.locale });
}
}, [resume, router]);

if (!resume || isEmpty(resume)) return null;

const layout: string[][][] = get(resume, 'metadata.layout', []);
Expand Down

0 comments on commit 62fd63e

Please sign in to comment.