Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari committed May 25, 2024
1 parent e17c4ec commit 672c261
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 37 deletions.
70 changes: 38 additions & 32 deletions packages/x-data-grid/src/locales/ruRU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,26 @@ import { ruRU as ruRUCore } from '@mui/material/locale';
import { GridLocaleText } from '../models/api/gridLocaleTextApi';
import { getGridLocalization, Localization } from '../utils/getGridLocalization';

type PluralForm = {
one: string;
few: string;
many: string;
};

function getPluralForm(count: number, options: PluralForm) {
const penultimateDigit = Math.floor(count / 10) % 10;
const lastDigit = count % 10;

let pluralForm = options.many;
if (penultimateDigit !== 1 && lastDigit > 1 && lastDigit < 5) {
pluralForm = options.few;
} else if (penultimateDigit !== 1 && lastDigit === 1) {
pluralForm = options.one;
}

return `${count} ${pluralForm}`;
}

const ruRUGrid: Partial<GridLocaleText> = {
// Root
noRowsLabel: 'Нет строк',
Expand All @@ -23,16 +43,12 @@ const ruRUGrid: Partial<GridLocaleText> = {
toolbarFiltersLabel: 'Показать фильтры',
toolbarFiltersTooltipHide: 'Скрыть фильтры',
toolbarFiltersTooltipShow: 'Показать фильтры',
toolbarFiltersTooltipActive: (count) => {
let pluralForm = 'активных фильтров';
const lastDigit = count % 10;
if (lastDigit > 1 && lastDigit < 5) {
pluralForm = 'активных фильтра';
} else if (lastDigit === 1) {
pluralForm = 'активный фильтр';
}
return `${count} ${pluralForm}`;
},
toolbarFiltersTooltipActive: (count) =>
getPluralForm(count, {
one: 'активный фильтр',
few: 'активных фильтра',
many: 'активных фильтров',
}),

// Quick filter toolbar field
toolbarQuickFilterPlaceholder: 'Поиск…',
Expand Down Expand Up @@ -122,32 +138,22 @@ const ruRUGrid: Partial<GridLocaleText> = {
columnMenuSortDesc: 'Сортировать по убыванию',

// Column header text
columnHeaderFiltersTooltipActive: (count) => {
let pluralForm = 'активных фильтров';
const lastDigit = count % 10;
if (lastDigit > 1 && lastDigit < 5) {
pluralForm = 'активных фильтра';
} else if (lastDigit === 1) {
pluralForm = 'активный фильтр';
}
return `${count} ${pluralForm}`;
},
columnHeaderFiltersTooltipActive: (count) =>
getPluralForm(count, {
one: 'активный фильтр',
few: 'активных фильтра',
many: 'активных фильтров',
}),
columnHeaderFiltersLabel: 'Показать фильтры',
columnHeaderSortIconLabel: 'Сортировать',

// Rows selected footer text
footerRowSelected: (count) => {
let pluralForm = 'строк выбрано';
const penultimateDigit = Math.floor(count / 10) % 10;
const lastDigit = count % 10;
if (penultimateDigit !== 1 && lastDigit > 1 && lastDigit < 5) {
pluralForm = 'строки выбраны';
} else if (penultimateDigit !== 1 && lastDigit === 1) {
pluralForm = 'строка выбрана';
}
return `${count} ${pluralForm}`;
},

footerRowSelected: (count) =>
getPluralForm(count, {
one: 'строка выбрана',
few: 'строки выбраны',
many: 'строк выбрано',
}),
// Total row amount footer text
footerTotalRows: 'Всего строк:',

Expand Down
11 changes: 6 additions & 5 deletions packages/x-data-grid/src/locales/ukUA.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,19 @@ type PluralForm = {
many: string;
};

const getPluralForm = (count: number, options: PluralForm) => {
let pluralForm = options.many;
function getPluralForm(count: number, options: PluralForm) {
const penultimateDigit = Math.floor(count / 10) % 10;
const lastDigit = count % 10;

if (lastDigit > 1 && lastDigit < 5) {
let pluralForm = options.many;
if (penultimateDigit !== 1 && lastDigit > 1 && lastDigit < 5) {
pluralForm = options.few;
} else if (lastDigit === 1) {
} else if (penultimateDigit !== 1 && lastDigit === 1) {
pluralForm = options.one;
}

return `${count} ${pluralForm}`;
};
}

const ukUAGrid: Partial<GridLocaleText> = {
// Root
Expand Down

0 comments on commit 672c261

Please sign in to comment.