fix(locale-core): plural numbers for russian or maybe slavic languages

This commit is contained in:
veselcraft 2025-03-16 17:16:44 +03:00
parent 2abf4f0bd6
commit c0efd19fcd
No known key found for this signature in database
GPG key ID: 9CF0B42766CCF7BA
2 changed files with 12 additions and 10 deletions

View file

@ -121,15 +121,17 @@ function tr(string $stringId, ...$variables): string
if (gettype($variables[0]) === "integer") { if (gettype($variables[0]) === "integer") {
$numberedStringId = null; $numberedStringId = null;
$cardinal = $variables[0]; $cardinal = $variables[0];
switch ($cardinal) { // WARNING: Hardcoded for russian language
case 0: if ($cardinal == 0) {
$numberedStringId = $stringId . "_zero"; $numberedStringId = $stringId . "_zero";
break; } else if ($cardinal == 1 || $cardinal % 10 == 1) {
case 1:
$numberedStringId = $stringId . "_one"; $numberedStringId = $stringId . "_one";
break; } else if (($cardinal % 10 >= 2 && $cardinal % 10 <= 4) || !($cardinal % 100 >= 12 && $cardinal % 100 <= 14)) {
default: $numberedStringId = $stringId . "_few";
$numberedStringId = $stringId . ($cardinal < 5 ? "_few" : "_other"); } 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); $newOutput = $localizer->_($numberedStringId, $lang);

View file

@ -84,7 +84,7 @@
"desc_none" = "описание отсутствует"; "desc_none" = "описание отсутствует";
"send" = "Отправить"; "send" = "Отправить";
"years_zero" = "0 лет"; "years_zero" = "0 лет";
"years_one" = "1 год"; "years_one" = "$1 год";
"years_few" = "$1 года"; "years_few" = "$1 года";
"years_many" = "$1 лет"; "years_many" = "$1 лет";
"years_other" = "$1 лет"; "years_other" = "$1 лет";