Answer the question
In order to leave comments, you need to log in
Correct translation of dates in wordpress?
Good afternoon, 3 days I've been struggling with dates on wordpress in the format ago
There is a jamb in the translation (declensions are not taken into account)
In the singular - month (month)
In the plural - months (months)
There is not enough rule for the number of months 2,3,4 ,22 etc.
How it is displayed:
Who rules?) Plugins like RussianDate do not help.
in POedit, this is how this system is implemented in the engine itself (not in the topic)
And like this in the topic:
Answer the question
In order to leave comments, you need to log in
Decision:
<?php
function declOfNum($number, $titles) {
$cases = array (2, 0, 1, 1, 1, 2);
return $titles[ ($number%100 > 4 && $number %100 < 20) ? 2 : $cases[min($number%10, 5)] ];
}
echo declOfNum($number, array('месяц', 'месяца', 'месяцев'));
// вместо $number выводи the_time(); или типо того
?>
<?php
echo '1 ' . declOfNum(1, array('месяц', 'месяца', 'месяцев')) . '<br/>';
echo '2 ' . declOfNum(2, array('месяц', 'месяца', 'месяцев')) . '<br/>';
echo '5 ' . declOfNum(5, array('месяц', 'месяца', 'месяцев')) . '<br/>';
?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question