From 95529f1d98244c297aa2c9a4ff09b282e83815d1 Mon Sep 17 00:00:00 2001 From: Sny Date: Mon, 25 Nov 2024 08:10:46 +0530 Subject: [PATCH] Org/Repo Summary | using singular/plural labels --- src/common/utils.js | 3 +++ src/components/orgs/OrgStatistics.jsx | 6 +++--- src/components/repos/RepoSummary.jsx | 12 ++++++------ src/i18n/locales/en/translations.json | 3 +++ 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/common/utils.js b/src/common/utils.js index 6a500460..37d4747f 100644 --- a/src/common/utils.js +++ b/src/common/utils.js @@ -996,3 +996,6 @@ export const highlightTexts = (items, texts, unmark=false) => { markInstance.unmark(options) markInstance.mark(_texts, options); } + +export const pluralize = (count, singular, plural) => `${count?.toLocaleString()} ${count === 1 ? singular : plural}`; + diff --git a/src/components/orgs/OrgStatistics.jsx b/src/components/orgs/OrgStatistics.jsx index 654a9094..7cbcd318 100644 --- a/src/components/orgs/OrgStatistics.jsx +++ b/src/components/orgs/OrgStatistics.jsx @@ -8,7 +8,7 @@ import ListItem from '@mui/material/ListItem'; import ListItemIcon from '@mui/material/ListItemIcon'; import ListItemText from '@mui/material/ListItemText'; import DateIcon from '@mui/icons-material/Today'; -import { formatDate } from '../../common/utils' +import { formatDate, pluralize } from '../../common/utils' import RepoIcon from '../repos/RepoIcon'; import MemberList from './MemberList' @@ -31,7 +31,7 @@ const OrgStatistics = ({ org, members }) => { setMembersOpen(true)}> @@ -40,7 +40,7 @@ const OrgStatistics = ({ org, members }) => { diff --git a/src/components/repos/RepoSummary.jsx b/src/components/repos/RepoSummary.jsx index 11f7a292..5ceb0c1c 100644 --- a/src/components/repos/RepoSummary.jsx +++ b/src/components/repos/RepoSummary.jsx @@ -18,7 +18,7 @@ import RefreshIcon from '@mui/icons-material/Refresh'; import isEmpty from 'lodash/isEmpty' import APIService from '../../services/APIService' -import { currentUserHasAccess } from '../../common/utils' +import { currentUserHasAccess, pluralize } from '../../common/utils' import { OperationsContext } from '../app/LayoutContext'; import AccessChip from '../common/AccessChip' import ConceptIcon from '../concepts/ConceptIcon' @@ -129,7 +129,7 @@ const RepoSummary = ({ repo, summary }) => { primary={ locales === false ? : - <>{`${locales?.toLocaleString()} ${t('repo.locales')}`} + <>{pluralize(locales, t('repo.locale'), t('repo.locales'))} } sx={{ '.MuiListItemText-primary': {fontSize: '12px', color: 'secondary.main'} @@ -144,7 +144,7 @@ const RepoSummary = ({ repo, summary }) => { primary={ conceptClasses === false ? : - <>{`${conceptClasses?.toLocaleString()} ${t('concept.concept_classes')}`} + <>{pluralize(conceptClasses, t('concept.concept_class'), t('concept.concept_classes'))} } sx={{ '.MuiListItemText-primary': {fontSize: '12px', color: 'secondary.main'} @@ -159,7 +159,7 @@ const RepoSummary = ({ repo, summary }) => { primary={ datatypes === false ? : - <>{`${datatypes?.toLocaleString()} ${t('concept.datatypes')}`} + <>{pluralize(datatypes, t('concept.datatype'), t('concept.datatypes'))} } sx={{ '.MuiListItemText-primary': {fontSize: '12px', color: 'secondary.main'} @@ -174,7 +174,7 @@ const RepoSummary = ({ repo, summary }) => { primary={ nameTypes === false ? : - <>{`${nameTypes?.toLocaleString()} ${t('concept.name_types')}`} + <>{pluralize(nameTypes, t('concept.name_types'), t('concept.name_types'))} } sx={{ '.MuiListItemText-primary': {fontSize: '12px', color: 'secondary.main'} @@ -189,7 +189,7 @@ const RepoSummary = ({ repo, summary }) => { primary={ mapTypes === false ? : - <>{`${mapTypes?.toLocaleString()} ${t('mapping.map_types')}`} + <>{pluralize(mapTypes, t('mapping.map_type'), t('mapping.map_types'))} } sx={{ '.MuiListItemText-primary': {fontSize: '12px', color: 'secondary.main'} diff --git a/src/i18n/locales/en/translations.json b/src/i18n/locales/en/translations.json index 51fcf12e..96de5e20 100644 --- a/src/i18n/locales/en/translations.json +++ b/src/i18n/locales/en/translations.json @@ -139,6 +139,7 @@ "copied_description": "Concept description URL copied to clipboard", "associations": "Associations", "concept_classes": "Concept Classes", + "name_type": "Name Type", "name_types": "Name Types", "form": { "id": "Concept ID", @@ -203,6 +204,7 @@ "compare": "Compare", "visibility": "Visibility", "locales": "Locales", + "locale": "Locale", "identifier": "Identifier", "contact": "Contact", "jurisdiction": "Jurisdiction", @@ -241,6 +243,7 @@ "org": "Organization", "about_the_org": "About the Organization", "members": "Members", + "member": "Member", "org_have_not_created_public_repos_suffix": "have not created any public repositories", "browse_members": "Browse members", "member_of": "Member of"