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/PostMeta/PostMeta.tsx | 118 ++++++++++++++++++++++++++--------- 1 file changed, 89 insertions(+), 29 deletions(-) (limited to 'src/components/PostMeta/PostMeta.tsx') diff --git a/src/components/PostMeta/PostMeta.tsx b/src/components/PostMeta/PostMeta.tsx index f95707a..86e4e71 100644 --- a/src/components/PostMeta/PostMeta.tsx +++ b/src/components/PostMeta/PostMeta.tsx @@ -1,9 +1,9 @@ import { config } from '@config/website'; -import { plural, t } from '@lingui/macro'; import { ArticleMeta } from '@ts/types/articles'; import { getFormattedDate } from '@utils/helpers/format'; import Link from 'next/link'; import { useRouter } from 'next/router'; +import { useIntl } from 'react-intl'; import styles from './PostMeta.module.scss'; type PostMetaMode = 'list' | 'single'; @@ -26,6 +26,7 @@ const PostMeta = ({ website, wordsCount, } = meta; + const intl = useIntl(); const router = useRouter(); const locale = router.locale ? router.locale : config.locales.defaultLocale; const isThematic = () => router.asPath.includes('/thematique/'); @@ -62,24 +63,31 @@ const PostMeta = ({ }; const getCommentsCount = () => { - switch (commentCount) { - case 0: - return t`No comments`; - case 1: - return t`1 comment`; - default: - return t`${commentCount} comments`; - } + return intl.formatMessage( + { + defaultMessage: + '{commentCount, plural, =0 {No comments} one {# comment} other {# comments}}', + description: 'PostMeta: comment count value', + }, + { commentCount } + ); }; const getReadingTime = () => { if (!readingTime) return; - if (readingTime < 0) return t`less than 1 minute`; - return plural(readingTime, { - zero: '# minutes', - one: '# minute', - other: '# minutes', - }); + if (readingTime < 0) + return intl.formatMessage({ + defaultMessage: 'less than 1 minute', + description: 'PostMeta: Reading time value', + }); + return intl.formatMessage( + { + defaultMessage: + '{readingTime, plural, =0 {# minutes} one {# minute} other {# minutes}}', + description: 'PostMeta: reading time value', + }, + { readingTime } + ); }; const getDates = () => { @@ -91,14 +99,24 @@ const PostMeta = ({ return ( <>
-
{t`Published on:`}
+
+ {intl.formatMessage({ + defaultMessage: 'Published on:', + description: 'PostMeta: publication date label', + })} +
{publicationDate !== updateDate && (
-
{t`Updated on:`}
+
+ {intl.formatMessage({ + defaultMessage: 'Updated on:', + description: 'PostMeta: update date label', + })} +
@@ -114,14 +132,24 @@ const PostMeta = ({
{author && (
-
{t`Written by:`}
+
+ {intl.formatMessage({ + defaultMessage: 'Written by:', + description: 'Article meta', + })} +
{author.name}
)} {getDates()} {readingTime !== undefined && wordsCount !== undefined && (
-
{t`Reading time:`}
+
+ {intl.formatMessage({ + defaultMessage: 'Reading time:', + description: 'Article meta', + })} +
-
{t`Total: `}
-
- {plural(results, { - zero: '# articles', - one: '# article', - other: '# articles', +
+ {intl.formatMessage({ + defaultMessage: 'Total:', + description: 'Article meta', })} +
+
+ {intl.formatMessage( + { + defaultMessage: + '{results, plural, =0 {No articles} one {# article} other {# articles}}', + description: 'PostMeta: total found articles', + }, + { results } + )}
)} {!isThematic() && thematics && thematics.length > 0 && (
- {thematics.length > 1 ? t`Thematics:` : t`Thematic:`} + {intl.formatMessage( + { + defaultMessage: + '{thematicsCount, plural, =0 {Thematics:} one {Thematic:} other {Thematics:}}', + description: 'PostMeta: thematics list label', + }, + { thematicsCount: thematics.length } + )}
{getThematics()}
@@ -153,14 +196,26 @@ const PostMeta = ({ {isThematic() && topics && topics.length > 0 && (
- {topics.length > 1 ? t`Topics:` : t`Topic:`} + {intl.formatMessage( + { + defaultMessage: + '{topicsCount, plural, =0 {Topics:} one {Topic:} other {Topics:}}', + description: 'PostMeta: topics list label', + }, + { topicsCount: topics.length } + )}
{getTopics()}
)} {website && (
-
{t`Website:`}
+
+ {intl.formatMessage({ + defaultMessage: 'Website:', + description: 'PostMeta: website label', + })} +
{website}
@@ -168,7 +223,12 @@ const PostMeta = ({ )} {commentCount !== undefined && (
-
{t`Comments:`}
+
+ {intl.formatMessage({ + defaultMessage: 'Comments:', + description: 'PostMeta: comment count label', + })} +
{isArticle() ? ( {getCommentsCount()} -- cgit v1.2.3