add declension of words
This commit is contained in:
@@ -5,6 +5,7 @@ import { useQuery } from '@tanstack/react-query';
|
||||
import { getUserFilesData } from '@/app/actions/fileEntity';
|
||||
import { getUserFilesInfo } from '@/app/actions/action';
|
||||
import { convertBytes } from '@/app/lib/convertBytes';
|
||||
import { pluralize } from '@/app/lib/pluralize';
|
||||
|
||||
type FilesInfo = {
|
||||
totalSize: number;
|
||||
@@ -69,6 +70,23 @@ export default function ProtectionSummary({ fileType }: { fileType: string }) {
|
||||
}
|
||||
});
|
||||
|
||||
const pluralizeFilesName = (number: number) => {
|
||||
const translate = [t(`${fileType}`), t(`${fileType}s-few`), t(`${fileType}s`)];
|
||||
return pluralize(number, translate[0], translate[1], translate[2]);
|
||||
};
|
||||
|
||||
const pluralizeCheks = (number: number) => {
|
||||
const translate = [t('check'), t('checks-few'), t('checks')];
|
||||
return pluralize(number, translate[0], translate[1], translate[2]);
|
||||
};
|
||||
|
||||
const pluralizeViolations = (number: number) => {
|
||||
const translate = [t('violation'), t('violations-few'), t('violations')];
|
||||
return pluralize(number, translate[0], translate[1], translate[2]);
|
||||
};
|
||||
|
||||
const CHECKS = 6;
|
||||
const VIOLATIONS = 2;
|
||||
|
||||
return (
|
||||
<div className="protection-overview grow">
|
||||
@@ -78,16 +96,18 @@ export default function ProtectionSummary({ fileType }: { fileType: string }) {
|
||||
<div className="protection-stat total-files">
|
||||
<div className="protection-stat-value">{filesInfo?.totalCount ? filesInfo?.totalCount : 0}</div>
|
||||
<div className="protection-stat-label">
|
||||
{t('total-files')}
|
||||
<br />
|
||||
({t(`${fileType}s`)})
|
||||
{pluralizeFilesName(filesInfo?.totalCount || 0)}
|
||||
</div>
|
||||
</div>
|
||||
<div className="protection-stat total-checks">
|
||||
<div className="protection-stat-value">0</div>
|
||||
<div className="protection-stat-label">{t('check')}</div>
|
||||
<div className="protection-stat-value">0</div>
|
||||
<div className="protection-stat-label">{t('violations')}</div>
|
||||
<div className="protection-stat-value">{CHECKS}</div>
|
||||
<div className="protection-stat-label">
|
||||
{pluralizeCheks(CHECKS)}
|
||||
</div>
|
||||
<div className="protection-stat-value">{VIOLATIONS}</div>
|
||||
<div className="protection-stat-label">
|
||||
{pluralizeViolations(VIOLATIONS)}
|
||||
</div>
|
||||
</div>
|
||||
<div className="protection-stat total-usage">
|
||||
<div className="protection-stat-value">{filesInfo?.totalSize ? convertBytes(filesInfo?.totalSize) : 0} / 0</div>
|
||||
|
||||
Reference in New Issue
Block a user