From 77a261393e4e5a954fb5ebd9ad99e063c72ba1a4 Mon Sep 17 00:00:00 2001 From: Kevin Stadler Date: Mon, 28 Oct 2024 12:54:36 +0100 Subject: [PATCH] improvement: properly handle single/plural messages --- components/instantsearch-stats.tsx | 6 +----- messages/en.json | 4 ++-- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/components/instantsearch-stats.tsx b/components/instantsearch-stats.tsx index f0fbc31..eb3e213 100644 --- a/components/instantsearch-stats.tsx +++ b/components/instantsearch-stats.tsx @@ -6,9 +6,5 @@ export function InstantSearchStats(): ReactNode { const t = useTranslations("SearchPage"); const stats = useStats(); // https://www.algolia.com/doc/api-reference/widgets/stats/react/#hook - return ( - <> - {stats.nbHits} {stats.nbHits === 1 ? t("result") : t("results")} - - ); + return <>{t("result", { count: stats.nbHits })}; } diff --git a/messages/en.json b/messages/en.json index 3849cd3..1bbdf3b 100644 --- a/messages/en.json +++ b/messages/en.json @@ -90,8 +90,8 @@ "work": "works" }, "query_placeholder": "search publications", - "result": "publication", - "results": "publications", + "result": "{count, plural, =1 {# publication} other {# publications}}", + "result_other": "publications", "show_more": "show more results", "sort_by": "sort by", "sort": {