From e17c4ec67fdc09519d68249885066094bbf6d46e Mon Sep 17 00:00:00 2001 From: Dastan Akhmetov Date: Mon, 27 Nov 2023 18:19:42 +0600 Subject: [PATCH 1/4] [locales] Use penultimate digit for russian in footer row selected (#11210) --- packages/x-data-grid/src/locales/ruRU.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/x-data-grid/src/locales/ruRU.ts b/packages/x-data-grid/src/locales/ruRU.ts index f08cfba7b4da..59fb08636c72 100644 --- a/packages/x-data-grid/src/locales/ruRU.ts +++ b/packages/x-data-grid/src/locales/ruRU.ts @@ -138,10 +138,11 @@ const ruRUGrid: Partial = { // Rows selected footer text footerRowSelected: (count) => { let pluralForm = 'строк выбрано'; + const penultimateDigit = Math.floor(count / 10) % 10; const lastDigit = count % 10; - if (lastDigit > 1 && lastDigit < 5) { + if (penultimateDigit !== 1 && lastDigit > 1 && lastDigit < 5) { pluralForm = 'строки выбраны'; - } else if (lastDigit === 1) { + } else if (penultimateDigit !== 1 && lastDigit === 1) { pluralForm = 'строка выбрана'; } return `${count} ${pluralForm}`; From 672c261756785c5a313e4a53a991f81a3e019451 Mon Sep 17 00:00:00 2001 From: Olivier Tassinari Date: Sat, 25 May 2024 19:22:39 +0200 Subject: [PATCH 2/4] cleanup --- packages/x-data-grid/src/locales/ruRU.ts | 70 +++++++++++++----------- packages/x-data-grid/src/locales/ukUA.ts | 11 ++-- 2 files changed, 44 insertions(+), 37 deletions(-) diff --git a/packages/x-data-grid/src/locales/ruRU.ts b/packages/x-data-grid/src/locales/ruRU.ts index 59fb08636c72..3b66f16d854d 100644 --- a/packages/x-data-grid/src/locales/ruRU.ts +++ b/packages/x-data-grid/src/locales/ruRU.ts @@ -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 = { // Root noRowsLabel: 'Нет строк', @@ -23,16 +43,12 @@ const ruRUGrid: Partial = { 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: 'Поиск…', @@ -122,32 +138,22 @@ const ruRUGrid: Partial = { 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: 'Всего строк:', diff --git a/packages/x-data-grid/src/locales/ukUA.ts b/packages/x-data-grid/src/locales/ukUA.ts index 22185c2c34e9..bfb45ead7c68 100644 --- a/packages/x-data-grid/src/locales/ukUA.ts +++ b/packages/x-data-grid/src/locales/ukUA.ts @@ -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 = { // Root From 8c7a442c70c686a7680ba2b153db9e51d68d6c01 Mon Sep 17 00:00:00 2001 From: Olivier Tassinari Date: Sat, 25 May 2024 19:32:22 +0200 Subject: [PATCH 3/4] l10n --- packages/x-data-grid/src/locales/ruRU.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/x-data-grid/src/locales/ruRU.ts b/packages/x-data-grid/src/locales/ruRU.ts index 3b66f16d854d..7312e34d60ba 100644 --- a/packages/x-data-grid/src/locales/ruRU.ts +++ b/packages/x-data-grid/src/locales/ruRU.ts @@ -154,6 +154,7 @@ const ruRUGrid: Partial = { few: 'строки выбраны', many: 'строк выбрано', }), + // Total row amount footer text footerTotalRows: 'Всего строк:', From 1d000eaf68fe36f9e75e9fc22060aecc0764f60d Mon Sep 17 00:00:00 2001 From: Olivier Tassinari Date: Sat, 25 May 2024 19:37:50 +0200 Subject: [PATCH 4/4] normalize --- packages/x-data-grid/src/locales/beBY.ts | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/x-data-grid/src/locales/beBY.ts b/packages/x-data-grid/src/locales/beBY.ts index d2aaaa7729c5..b10dd30d81fd 100644 --- a/packages/x-data-grid/src/locales/beBY.ts +++ b/packages/x-data-grid/src/locales/beBY.ts @@ -4,16 +4,16 @@ import { getGridLocalization, Localization } from '../utils/getGridLocalization' type PluralForm = { one: string; - twoToFour: string; - other: string; + few: string; + many: string; }; const getPluralForm = (count: number, options: PluralForm) => { - let pluralForm = options.other; + let pluralForm = options.many; const lastDigit = count % 10; if (lastDigit > 1 && lastDigit < 5 && (count < 10 || count > 20)) { - pluralForm = options.twoToFour; + pluralForm = options.few; } else if (lastDigit === 1 && count % 100 !== 11) { pluralForm = options.one; } @@ -45,8 +45,8 @@ const beBYGrid: Partial = { toolbarFiltersTooltipActive: (count) => getPluralForm(count, { one: 'актыўны фільтр', - twoToFour: 'актыўных фільтра', - other: 'актыўных фільтраў', + few: 'актыўных фільтра', + many: 'актыўных фільтраў', }), // Quick filter toolbar field @@ -140,8 +140,8 @@ const beBYGrid: Partial = { columnHeaderFiltersTooltipActive: (count) => getPluralForm(count, { one: 'актыўны фільтр', - twoToFour: 'актыўных фільтра', - other: 'актыўных фільтраў', + few: 'актыўных фільтра', + many: 'актыўных фільтраў', }), columnHeaderFiltersLabel: 'Паказаць фільтры', columnHeaderSortIconLabel: 'Сартыраваць', @@ -150,8 +150,8 @@ const beBYGrid: Partial = { footerRowSelected: (count) => getPluralForm(count, { one: 'абраны радок', - twoToFour: 'абраных радка', - other: 'абраных радкоў', + few: 'абраных радка', + many: 'абраных радкоў', }), // Total row amount footer text