2026-01-08 17:21:09 +07:00
|
|
|
export const pluralize = (number: number, one: string, few: string, many: string) => {
|
2026-01-12 17:31:42 +07:00
|
|
|
const currentLang = document.documentElement.getAttribute('lang') || 'ru';
|
2026-01-08 17:21:09 +07:00
|
|
|
|
2026-01-12 17:31:42 +07:00
|
|
|
if (currentLang === 'ru') {
|
|
|
|
|
const n = Math.abs(number) % 100;
|
|
|
|
|
const n1 = n % 10;
|
2026-01-08 17:21:09 +07:00
|
|
|
|
2026-01-12 17:31:42 +07:00
|
|
|
if (n > 10 && n < 20) return many; // 11-19
|
|
|
|
|
if (n1 > 1 && n1 < 5) return few; // 2-4 (кроме 12-14)
|
|
|
|
|
if (n1 === 1) return one; // 1 (кроме 11)
|
|
|
|
|
|
|
|
|
|
return many; // 0, 5-9, 10-20, 25-30 и т.д.
|
|
|
|
|
} else {
|
|
|
|
|
if (number === 1 || number === 0) return one;
|
|
|
|
|
return many;
|
|
|
|
|
}
|
2026-01-08 17:21:09 +07:00
|
|
|
};
|