Skip to content

Commit

Permalink
Org/Repo Summary | using singular/plural labels
Browse files Browse the repository at this point in the history
  • Loading branch information
snyaggarwal committed Nov 25, 2024
1 parent 0600bd1 commit 95529f1
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
3 changes: 3 additions & 0 deletions src/common/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;

6 changes: 3 additions & 3 deletions src/components/orgs/OrgStatistics.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -31,7 +31,7 @@ const OrgStatistics = ({ org, members }) => {
</ListItemIcon>
<ListItemText
sx={{color: 'default.light', '.MuiListItemText-primary': {fontSize: '12px'}}}
primary={`${repos} ${t('common.public').toLowerCase()} ${t('repo.repos').toLowerCase()}`}
primary={pluralize(repos, t('common.public').toLowerCase() + ' ' + t('repo.repo').toLowerCase(), t('common.public').toLowerCase() + ' ' + t('repo.repos').toLowerCase())}
/>
</ListItem>
<ListItem disablePadding sx={{marginTop: '8px', cursor: 'pointer'}} onClick={() => setMembersOpen(true)}>
Expand All @@ -40,7 +40,7 @@ const OrgStatistics = ({ org, members }) => {
</ListItemIcon>
<ListItemText
sx={{color: 'default.light', '.MuiListItemText-primary': {fontSize: '12px'}}}
primary={`${org.members} ${t('org.members').toLowerCase()}`}
primary={pluralize(org.members, t('org.member').toLowerCase(), t('org.members').toLowerCase())}
/>
</ListItem>
<ListItem disablePadding>
Expand Down
12 changes: 6 additions & 6 deletions src/components/repos/RepoSummary.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -129,7 +129,7 @@ const RepoSummary = ({ repo, summary }) => {
primary={
locales === false ?
<SkeletonText /> :
<>{`${locales?.toLocaleString()} ${t('repo.locales')}`}</>
<>{pluralize(locales, t('repo.locale'), t('repo.locales'))}</>
}
sx={{
'.MuiListItemText-primary': {fontSize: '12px', color: 'secondary.main'}
Expand All @@ -144,7 +144,7 @@ const RepoSummary = ({ repo, summary }) => {
primary={
conceptClasses === false ?
<SkeletonText /> :
<>{`${conceptClasses?.toLocaleString()} ${t('concept.concept_classes')}`}</>
<>{pluralize(conceptClasses, t('concept.concept_class'), t('concept.concept_classes'))}</>
}
sx={{
'.MuiListItemText-primary': {fontSize: '12px', color: 'secondary.main'}
Expand All @@ -159,7 +159,7 @@ const RepoSummary = ({ repo, summary }) => {
primary={
datatypes === false ?
<SkeletonText /> :
<>{`${datatypes?.toLocaleString()} ${t('concept.datatypes')}`}</>
<>{pluralize(datatypes, t('concept.datatype'), t('concept.datatypes'))}</>
}
sx={{
'.MuiListItemText-primary': {fontSize: '12px', color: 'secondary.main'}
Expand All @@ -174,7 +174,7 @@ const RepoSummary = ({ repo, summary }) => {
primary={
nameTypes === false ?
<SkeletonText /> :
<>{`${nameTypes?.toLocaleString()} ${t('concept.name_types')}`}</>
<>{pluralize(nameTypes, t('concept.name_types'), t('concept.name_types'))}</>
}
sx={{
'.MuiListItemText-primary': {fontSize: '12px', color: 'secondary.main'}
Expand All @@ -189,7 +189,7 @@ const RepoSummary = ({ repo, summary }) => {
primary={
mapTypes === false ?
<SkeletonText /> :
<>{`${mapTypes?.toLocaleString()} ${t('mapping.map_types')}`}</>
<>{pluralize(mapTypes, t('mapping.map_type'), t('mapping.map_types'))}</>
}
sx={{
'.MuiListItemText-primary': {fontSize: '12px', color: 'secondary.main'}
Expand Down
3 changes: 3 additions & 0 deletions src/i18n/locales/en/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -203,6 +204,7 @@
"compare": "Compare",
"visibility": "Visibility",
"locales": "Locales",
"locale": "Locale",
"identifier": "Identifier",
"contact": "Contact",
"jurisdiction": "Jurisdiction",
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 95529f1

Please sign in to comment.