From cf670af4035dc9b462cf5b1aad06ca089cf1d40c Mon Sep 17 00:00:00 2001 From: Amruth Pillai Date: Sat, 12 Mar 2022 19:46:30 +0100 Subject: [PATCH] fix(client): exported pdf did not contain "Present" keyword with translations --- .../components/build/RightSidebar/sections/Settings.tsx | 1 + client/components/shared/LanguageSwitcher.tsx | 6 ++++++ client/pages/[username]/[slug]/printer.tsx | 9 +++++++-- schema/src/metadata.ts | 1 + server/src/resume/data/defaultState.ts | 1 + server/src/resume/data/sampleData.ts | 1 + 6 files changed, 17 insertions(+), 2 deletions(-) diff --git a/client/components/build/RightSidebar/sections/Settings.tsx b/client/components/build/RightSidebar/sections/Settings.tsx index 5cb2e005..ad88b259 100644 --- a/client/components/build/RightSidebar/sections/Settings.tsx +++ b/client/components/build/RightSidebar/sections/Settings.tsx @@ -66,6 +66,7 @@ const Settings = () => { const code = value?.code || 'en'; document.cookie = `NEXT_LOCALE=${code}; path=/; expires=2147483647`; + dispatch(setResumeState({ path: 'metadata.locale', value: code })); push({ pathname, query }, asPath, { locale: code }); }; diff --git a/client/components/shared/LanguageSwitcher.tsx b/client/components/shared/LanguageSwitcher.tsx index 012c0307..252962fe 100644 --- a/client/components/shared/LanguageSwitcher.tsx +++ b/client/components/shared/LanguageSwitcher.tsx @@ -5,6 +5,8 @@ import { useTranslation } from 'next-i18next'; import { MouseEvent, useState } from 'react'; import { languages } from '@/config/languages'; +import { useAppDispatch } from '@/store/hooks'; +import { setResumeState } from '@/store/resume/resumeSlice'; import styles from './LanguageSwitcher.module.scss'; @@ -13,6 +15,8 @@ const LanguageSwitcher = () => { const { t } = useTranslation(); + const dispatch = useAppDispatch(); + const [anchorEl, setAnchorEl] = useState(null); const handleClick = (event: MouseEvent) => setAnchorEl(event.currentTarget); @@ -23,6 +27,8 @@ const LanguageSwitcher = () => { const { pathname, asPath, query } = router; document.cookie = `NEXT_LOCALE=${locale}; path=/; expires=2147483647`; + dispatch(setResumeState({ path: 'metadata.locale', value: locale })); + router.push({ pathname, query }, asPath, { locale }); }; diff --git a/client/pages/[username]/[slug]/printer.tsx b/client/pages/[username]/[slug]/printer.tsx index b691d4fe..b0aa8de3 100644 --- a/client/pages/[username]/[slug]/printer.tsx +++ b/client/pages/[username]/[slug]/printer.tsx @@ -3,6 +3,7 @@ import clsx from 'clsx'; import get from 'lodash/get'; import isEmpty from 'lodash/isEmpty'; import { GetServerSideProps, NextPage } from 'next'; +import { serverSideTranslations } from 'next-i18next/serverSideTranslations'; import { useEffect } from 'react'; import Page from '@/components/build/Center/Page'; @@ -22,15 +23,19 @@ type Props = { redirect?: any; }; -export const getServerSideProps: GetServerSideProps, QueryParams> = async ({ query }) => { +export const getServerSideProps: GetServerSideProps, QueryParams> = async ({ + query, + locale, +}) => { const { username, slug, secretKey } = query as QueryParams; try { if (isEmpty(secretKey)) throw new Error('There is no secret key!'); const resume = await fetchResumeByIdentifier({ username, slug, options: { secretKey } }); + const displayLocale = resume.metadata.locale || locale || 'en'; - return { props: { resume } }; + return { props: { resume, ...(await serverSideTranslations(displayLocale, ['common'])) } }; } catch (error) { return { redirect: { diff --git a/schema/src/metadata.ts b/schema/src/metadata.ts index 9a4968c7..67981bd8 100644 --- a/schema/src/metadata.ts +++ b/schema/src/metadata.ts @@ -23,6 +23,7 @@ export type DateConfig = { export type Metadata = { css: CustomCSS; + locale: string; date: DateConfig; layout: string[][][]; // page.column.section template: string; diff --git a/server/src/resume/data/defaultState.ts b/server/src/resume/data/defaultState.ts index 839d8ebf..11bda420 100644 --- a/server/src/resume/data/defaultState.ts +++ b/server/src/resume/data/defaultState.ts @@ -133,6 +133,7 @@ const defaultState: Partial = { background: '#ffffff', primary: '#f44336', }, + locale: 'en', date: { format: 'MMMM DD, YYYY', }, diff --git a/server/src/resume/data/sampleData.ts b/server/src/resume/data/sampleData.ts index 55c982a2..48671e95 100644 --- a/server/src/resume/data/sampleData.ts +++ b/server/src/resume/data/sampleData.ts @@ -421,6 +421,7 @@ const sampleData: Partial = { value: '/* Enter custom CSS here */\n\n* {\n outline: 1px solid #000;\n}', visible: false, }, + locale: 'en', date: { format: 'MMMM DD, YYYY', },