From c0efd19fcd31d6a110756b89aa7df92ff9ca64c0 Mon Sep 17 00:00:00 2001 From: veselcraft Date: Sun, 16 Mar 2025 17:16:44 +0300 Subject: [PATCH] fix(locale-core): plural numbers for russian or maybe slavic languages --- bootstrap.php | 20 +++++++++++--------- locales/ru.strings | 2 +- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/bootstrap.php b/bootstrap.php index 3fac8214..2833c154 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -121,15 +121,17 @@ function tr(string $stringId, ...$variables): string if (gettype($variables[0]) === "integer") { $numberedStringId = null; $cardinal = $variables[0]; - switch ($cardinal) { - case 0: - $numberedStringId = $stringId . "_zero"; - break; - case 1: - $numberedStringId = $stringId . "_one"; - break; - default: - $numberedStringId = $stringId . ($cardinal < 5 ? "_few" : "_other"); + // WARNING: Hardcoded for russian language + if ($cardinal == 0) { + $numberedStringId = $stringId . "_zero"; + } else if ($cardinal == 1 || $cardinal % 10 == 1) { + $numberedStringId = $stringId . "_one"; + } else if (($cardinal % 10 >= 2 && $cardinal % 10 <= 4) || !($cardinal % 100 >= 12 && $cardinal % 100 <= 14)) { + $numberedStringId = $stringId . "_few"; + } else if ($cardinal % 10 == 0 || ($cardinal % 10 >= 5 && $cardinal % 10 <= 9) || ($cardinal % 100 >= 11 && $cardinal % 100 <= 14)) { + $numberedStringId = $stringId . "_many"; + } else { + $numberedStringId = $stringId . "_other"; } $newOutput = $localizer->_($numberedStringId, $lang); diff --git a/locales/ru.strings b/locales/ru.strings index 14f6f624..37b92768 100644 --- a/locales/ru.strings +++ b/locales/ru.strings @@ -84,7 +84,7 @@ "desc_none" = "описание отсутствует"; "send" = "Отправить"; "years_zero" = "0 лет"; -"years_one" = "1 год"; +"years_one" = "$1 год"; "years_few" = "$1 года"; "years_many" = "$1 лет"; "years_other" = "$1 лет";