C
C
CostPer2015-07-07 21:59:33
Machine translation from one language to another
CostPer, 2015-07-07 21:59:33

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:
16d6204192624bd8a411cb9499add0ff.png
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)
1aa324b9a0274a20962d0f39cbc8cfcb.png
And like this in the topic:
9c9dc82cdc964382bde6314ba9d386e0.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman, 2015-07-07
@llgruff

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(); или типо того
?>

For check:
<?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 question

Ask a Question

731 491 924 answers to any question