Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(theme-classic): should use plurals for category items description #9851

Merged
merged 3 commits into from
Feb 15, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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',
Copy link
Collaborator

@slorber slorber Feb 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a .plurals suffix to this id?

We usually have this convention to quickly identify strings that support plural rules.

Also need to rename all existing keys in docusaurus-theme-translations.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the review
i pushed the changes you requested

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