From e4d5b8151802517b2943756fc0d09ffa95e2c4e2 Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Sat, 29 Jan 2022 18:21:37 +0100 Subject: chore: replace lingui functions with react-intl --- src/components/Branding/Branding.tsx | 24 +- src/components/Breadcrumb/Breadcrumb.tsx | 46 +- .../Buttons/ButtonToolbar/ButtonToolbar.tsx | 27 +- src/components/Comment/Comment.tsx | 39 +- src/components/CommentForm/CommentForm.tsx | 45 +- src/components/CommentsList/CommentsList.tsx | 20 +- src/components/Footer/Footer.tsx | 10 +- src/components/FooterNav/FooterNav.tsx | 18 +- src/components/Icons/Copyright/Copyright.tsx | 3 +- src/components/Icons/Moon/Moon.tsx | 11 +- src/components/Icons/Sun/Sun.tsx | 11 +- src/components/Layouts/Layout.tsx | 14 +- src/components/MDX/CodeBlock/CodeBlock.tsx | 6 +- src/components/MainNav/MainNav.tsx | 66 ++- .../PaginationCursor/PaginationCursor.tsx | 21 +- src/components/PostFooter/PostFooter.tsx | 11 +- src/components/PostMeta/PostMeta.tsx | 118 ++++- src/components/PostPreview/PostPreview.tsx | 31 +- src/components/PostsList/PostsList.tsx | 25 +- src/components/ProjectPreview/ProjectPreview.tsx | 22 +- src/components/ProjectSummary/ProjectSummary.tsx | 68 ++- src/components/SearchForm/SearchForm.tsx | 17 +- .../Settings/ReduceMotion/ReduceMotion.tsx | 18 +- src/components/Settings/Settings.tsx | 10 +- .../Settings/ThemeToggle/ThemeToggle.tsx | 8 +- src/components/Spinner/Spinner.tsx | 11 +- .../ExpandableWidget/ExpandableWidget.tsx | 13 +- src/components/Widgets/CVPreview/CVPreview.tsx | 16 +- src/components/Widgets/RecentPosts/RecentPosts.tsx | 16 +- .../Widgets/RelatedThematics/RelatedThematics.tsx | 12 +- .../Widgets/RelatedTopics/RelatedTopics.tsx | 12 +- src/components/Widgets/Sharing/Sharing.tsx | 42 +- .../Widgets/ThematicsList/ThematicsList.tsx | 13 +- src/components/Widgets/ToC/ToC.tsx | 8 +- src/components/Widgets/TopicsList/TopicsList.tsx | 13 +- src/config/nav.ts | 14 - src/config/seo.ts | 33 -- src/config/sharing.ts | 4 +- src/config/website.ts | 4 +- src/i18n/en.json | 586 +++++++++++++++++++++ src/i18n/fr.json | 586 +++++++++++++++++++++ src/pages/404.tsx | 62 ++- src/pages/article/[slug].tsx | 6 +- src/pages/blog/index.tsx | 78 ++- src/pages/contact.tsx | 95 +++- src/pages/cv.tsx | 55 +- src/pages/index.tsx | 69 ++- src/pages/mentions-legales.tsx | 35 +- src/pages/projets.tsx | 30 +- src/pages/recherche/index.tsx | 68 ++- src/pages/sujet/[slug].tsx | 20 +- src/pages/thematique/[slug].tsx | 20 +- src/utils/helpers/i18n.ts | 23 +- src/utils/helpers/prism.ts | 22 +- 54 files changed, 2314 insertions(+), 341 deletions(-) delete mode 100644 src/config/nav.ts delete mode 100644 src/config/seo.ts create mode 100644 src/i18n/en.json create mode 100644 src/i18n/fr.json (limited to 'src') diff --git a/src/components/Branding/Branding.tsx b/src/components/Branding/Branding.tsx index 01948e9..efb3a49 100644 --- a/src/components/Branding/Branding.tsx +++ b/src/components/Branding/Branding.tsx @@ -1,17 +1,18 @@ -import Image from 'next/image'; -import Link from 'next/link'; -import { ReactElement } from 'react'; -import { t } from '@lingui/macro'; import photo from '@assets/images/armand-philippot.jpg'; import { config } from '@config/website'; -import styles from './Branding.module.scss'; import Head from 'next/head'; +import Image from 'next/image'; +import Link from 'next/link'; +import { ReactElement } from 'react'; +import { useIntl } from 'react-intl'; import { Person, WithContext } from 'schema-dts'; +import styles from './Branding.module.scss'; import Logo from './Logo/Logo'; type BrandingReturn = ({ isHome }: { isHome: boolean }) => ReactElement; const Branding: BrandingReturn = ({ isHome = false }) => { + const intl = useIntl(); const TitleTag = isHome ? 'h1' : 'p'; const schemaJsonLd: WithContext = { @@ -38,10 +39,15 @@ const Branding: BrandingReturn = ({ isHome = false }) => {
{t({
diff --git a/src/components/Breadcrumb/Breadcrumb.tsx b/src/components/Breadcrumb/Breadcrumb.tsx index 7c8eb5c..30179be 100644 --- a/src/components/Breadcrumb/Breadcrumb.tsx +++ b/src/components/Breadcrumb/Breadcrumb.tsx @@ -1,12 +1,13 @@ import { config } from '@config/website'; -import { t } from '@lingui/macro'; import Head from 'next/head'; import Link from 'next/link'; import { useRouter } from 'next/router'; +import { useIntl } from 'react-intl'; import { BreadcrumbList, WithContext } from 'schema-dts'; import styles from './Breadcrumb.module.scss'; const Breadcrumb = ({ pageTitle }: { pageTitle: string }) => { + const intl = useIntl(); const router = useRouter(); const isHome = router.pathname === '/'; @@ -20,14 +21,24 @@ const Breadcrumb = ({ pageTitle }: { pageTitle: string }) => { <>
  • - {t`Home`} + + {intl.formatMessage({ + defaultMessage: 'Home', + description: 'Breadcrumb: Home item', + })} +
  • {(isArticle || isThematic || isSubject) && ( <>
  • - {t`Blog`} + + {intl.formatMessage({ + defaultMessage: 'Blog', + description: 'Breadcrumb: Blog item', + })} +
  • @@ -36,7 +47,12 @@ const Breadcrumb = ({ pageTitle }: { pageTitle: string }) => { <>
  • - {t`Projects`} + + {intl.formatMessage({ + defaultMessage: 'Projects', + description: 'Breadcrumb: Projects item', + })} +
  • @@ -51,7 +67,10 @@ const Breadcrumb = ({ pageTitle }: { pageTitle: string }) => { const homepage: BreadcrumbList['itemListElement'] = { '@type': 'ListItem', position: 1, - name: t`Home`, + name: intl.formatMessage({ + defaultMessage: 'Home', + description: 'Breadcrumb: Home item', + }), item: config.url, }; @@ -61,7 +80,10 @@ const Breadcrumb = ({ pageTitle }: { pageTitle: string }) => { const blog: BreadcrumbList['itemListElement'] = { '@type': 'ListItem', position: 2, - name: t`Blog`, + name: intl.formatMessage({ + defaultMessage: 'Blog', + description: 'Breadcrumb: Blog item', + }), item: `${config.url}/blog`, }; @@ -72,7 +94,10 @@ const Breadcrumb = ({ pageTitle }: { pageTitle: string }) => { const blog: BreadcrumbList['itemListElement'] = { '@type': 'ListItem', position: 2, - name: t`Projects`, + name: intl.formatMessage({ + defaultMessage: 'Projects', + description: 'Breadcrumb: Projects item', + }), item: `${config.url}/projets`, }; @@ -108,7 +133,12 @@ const Breadcrumb = ({ pageTitle }: { pageTitle: string }) => { {!isHome && ( )} diff --git a/src/components/Buttons/ButtonToolbar/ButtonToolbar.tsx b/src/components/Buttons/ButtonToolbar/ButtonToolbar.tsx index 246ad80..e9f6079 100644 --- a/src/components/Buttons/ButtonToolbar/ButtonToolbar.tsx +++ b/src/components/Buttons/ButtonToolbar/ButtonToolbar.tsx @@ -1,6 +1,6 @@ import { CloseIcon, CogIcon, SearchIcon } from '@components/Icons'; -import { t } from '@lingui/macro'; import { ForwardedRef, forwardRef, SetStateAction } from 'react'; +import { useIntl } from 'react-intl'; import styles from '../Buttons.module.scss'; type ButtonType = 'search' | 'settings'; @@ -17,6 +17,7 @@ const ButtonToolbar = ( }, ref: ForwardedRef ) => { + const intl = useIntl(); const ButtonIcon = () => (type === 'search' ? : ); const btnClasses = isActivated ? `${styles.toolbar} ${styles['toolbar--activated']}` @@ -38,9 +39,29 @@ const ButtonToolbar = ( {isActivated ? ( - {t`Close ${type}`} + + {intl.formatMessage( + { + defaultMessage: 'Close {type}', + description: 'ButtonToolbar: Close button', + }, + { + type, + } + )} + ) : ( - {t`Open ${type}`} + + {intl.formatMessage( + { + defaultMessage: 'Open {type}', + description: 'ButtonToolbar: Open button', + }, + { + type, + } + )} + )} ); diff --git a/src/components/Comment/Comment.tsx b/src/components/Comment/Comment.tsx index 6eb0184..e95a378 100644 --- a/src/components/Comment/Comment.tsx +++ b/src/components/Comment/Comment.tsx @@ -1,7 +1,6 @@ import { Button } from '@components/Buttons'; import CommentForm from '@components/CommentForm/CommentForm'; import { config } from '@config/website'; -import { t } from '@lingui/macro'; import { Comment as CommentData } from '@ts/types/comments'; import { getFormattedDate } from '@utils/helpers/format'; import Head from 'next/head'; @@ -9,6 +8,7 @@ import Image from 'next/image'; import Link from 'next/link'; import { useRouter } from 'next/router'; import { useEffect, useRef, useState } from 'react'; +import { useIntl } from 'react-intl'; import { Comment as CommentSchema, WithContext } from 'schema-dts'; import styles from './Comment.module.scss'; @@ -21,6 +21,7 @@ const Comment = ({ comment: CommentData; isNested?: boolean; }) => { + const intl = useIntl(); const router = useRouter(); const locale = router.locale ? router.locale : config.locales.defaultLocale; const [isReply, setIsReply] = useState(false); @@ -48,7 +49,16 @@ const Comment = ({ minute: 'numeric', }) .replace(':', 'h'); - return t`${date} at ${time}`; + return intl.formatMessage( + { + defaultMessage: '{date} at {time}', + description: 'Comment: publication date', + }, + { + date, + time, + } + ); }; const getApprovedComment = () => { @@ -68,7 +78,12 @@ const Comment = ({ {getCommentAuthor()}
    -
    {t`Published on:`}
    +
    + {intl.formatMessage({ + defaultMessage: 'Published on:', + description: 'Comment: publication date label', + })} +