Answer the question
In order to leave comments, you need to log in
How to implement case declension in Yii2?
What is the best way to implement word declensions by cases in Yii2, what would be written 2 vacancies I found, 100 vacancies Y found, 5 vacancies Y found, 1 vacancy Y found , etc...
Answer the question
In order to leave comments, you need to log in
I have used this feature before. I don't know how bad it is:
class Helper
{
/**
* Выбирает слово с правильными окончанием после числительного.
*
* @param int $number число
* @param array $words варианты склонений ['яблоко', 'яблока', 'яблок']
* @return string
*/
public static function plural(int $number, array $words): string
{
return $words[($number % 100 > 4 && $number % 100 < 20) ? 2 : [2, 0, 1, 1, 1, 2][min($number % 10, 5)]];
}
}
// echo "Загружено $count " . Helper::plural($count, ['запись', 'записи', 'записей'];
https://yiiframework.ru/forum/viewtopic.php?t=22495
well, or google yii2 russian plural form
RTFM https://github.com/yiisoft/yii2/blob/master/docs/g...
A way to inflect arbitrary words has already been invented: morphos.io/try/numerals?number=5&word=%D1%81%D0%BE...
And an adapter for yii2 - https://github.com/wapmorgan/yii2-inflection
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question