Skip to content

Commit

Permalink
fix(theme-classic): should use plurals for category items description
Browse files Browse the repository at this point in the history
  • Loading branch information
Нуриль Барадусов committed Feb 15, 2024
1 parent 6fd8408 commit fabaa7c
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions packages/docusaurus-theme-classic/src/theme/DocCard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
findFirstSidebarItemLink,
useDocById,
} from '@docusaurus/theme-common/internal';
import {usePluralForm} from '@docusaurus/theme-common';
import isInternalUrl from '@docusaurus/isInternalUrl';
import {translate} from '@docusaurus/Translate';

Expand All @@ -24,6 +25,23 @@ import type {

import styles from './styles.module.css';

function useCategoryItemsPlural() {
const {selectMessage} = usePluralForm();
return (count: number) =>
selectMessage(
count,
translate(
{
message: '{count} items',
id: 'theme.docs.DocCard.categoryDescription',
description:
'The default description for a category card in the generated index about how many items this category includes',
},
{count},
),
);
}

function CardContainer({
href,
children,
Expand Down Expand Up @@ -76,6 +94,7 @@ function CardCategory({
item: PropSidebarItemCategory;
}): JSX.Element | null {
const href = findFirstSidebarItemLink(item);
const categoryItemsPlural = useCategoryItemsPlural();

// Unexpected: categories that don't have a link have been filtered upfront
if (!href) {
Expand All @@ -87,18 +106,7 @@ function CardCategory({
href={href}
icon="🗃️"
title={item.label}
description={
item.description ??
translate(
{
message: '{count} items',
id: 'theme.docs.DocCard.categoryDescription',
description:
'The default description for a category card in the generated index about how many items this category includes',
},
{count: item.items.length},
)
}
description={item.description ?? categoryItemsPlural(item.items.length)}
/>
);
}
Expand Down

0 comments on commit fabaa7c

Please sign in to comment.