diff --git a/src/Twig/AppExtension.php b/src/Twig/AppExtension.php index 512e626..6cf5813 100644 --- a/src/Twig/AppExtension.php +++ b/src/Twig/AppExtension.php @@ -77,21 +77,42 @@ class AppExtension extends AbstractExtension $values = [ - 365 * 24 * 60 * 60 => $this->translator->trans('year ago'), - 30 * 24 * 60 * 60 => $this->translator->trans('month ago'), - 24 * 60 * 60 => $this->translator->trans('day ago'), - 60 * 60 => $this->translator->trans('hour ago'), - 60 => $this->translator->trans('minute ago'), - 1 => $this->translator->trans('second ago') - ]; - - $plural = [ - $this->translator->trans('year ago') => $this->translator->trans('years ago'), - $this->translator->trans('month ago') => $this->translator->trans('months ago'), - $this->translator->trans('day ago') => $this->translator->trans('days ago'), - $this->translator->trans('hour ago') => $this->translator->trans('hours ago'), - $this->translator->trans('minute ago') => $this->translator->trans('minutes ago'), - $this->translator->trans('second ago') => $this->translator->trans('seconds ago') + 365 * 24 * 60 * 60 => + [ + $this->translator->trans('year ago'), + $this->translator->trans('years ago'), + $this->translator->trans(' years ago') + ], + 30 * 24 * 60 * 60 => + [ + $this->translator->trans('month ago'), + $this->translator->trans('months ago'), + $this->translator->trans(' months ago') + ], + 24 * 60 * 60 => + [ + $this->translator->trans('day ago'), + $this->translator->trans('days ago'), + $this->translator->trans(' days ago') + ], + 60 * 60 => + [ + $this->translator->trans('hour ago'), + $this->translator->trans('hours ago'), + $this->translator->trans(' hours ago') + ], + 60 => + [ + $this->translator->trans('minute ago'), + $this->translator->trans('minutes ago'), + $this->translator->trans(' minutes ago') + ], + 1 => + [ + $this->translator->trans('second ago'), + $this->translator->trans('seconds ago'), + $this->translator->trans(' seconds ago') + ] ]; foreach ($values as $key => $value) @@ -105,9 +126,19 @@ class AppExtension extends AbstractExtension return sprintf( '%s %s', $round, - $round > 1 ? $plural[$value] : $value + $this->plural( + $round, + $value + ) ); } } } + + private function plural(int $number, array $texts) + { + $cases = [2, 0, 1, 1, 1, 2]; + + return $texts[(($number % 100) > 4 && ($number % 100) < 20) ? 2 : $cases[min($number % 10, 5)]]; + } } \ No newline at end of file diff --git a/translations/messages+intl-icu.cs.xlf b/translations/messages+intl-icu.cs.xlf index 6d443b2..e31d182 100644 --- a/translations/messages+intl-icu.cs.xlf +++ b/translations/messages+intl-icu.cs.xlf @@ -693,6 +693,30 @@ seconds ago seconds ago + + years ago + years ago + + + months ago + months ago + + + days ago + days ago + + + hours ago + hours ago + + + minutes ago + minutes ago + + + seconds ago + seconds ago + diff --git a/translations/messages+intl-icu.de.xlf b/translations/messages+intl-icu.de.xlf index 65f9d0f..ea05fbf 100644 --- a/translations/messages+intl-icu.de.xlf +++ b/translations/messages+intl-icu.de.xlf @@ -693,6 +693,30 @@ seconds ago seconds ago + + years ago + years ago + + + months ago + months ago + + + days ago + days ago + + + hours ago + hours ago + + + minutes ago + minutes ago + + + seconds ago + seconds ago + diff --git a/translations/messages+intl-icu.en.xlf b/translations/messages+intl-icu.en.xlf index 645cd13..ce8592b 100644 --- a/translations/messages+intl-icu.en.xlf +++ b/translations/messages+intl-icu.en.xlf @@ -693,6 +693,30 @@ seconds ago seconds ago + + years ago + years ago + + + months ago + months ago + + + days ago + days ago + + + hours ago + hours ago + + + minutes ago + minutes ago + + + seconds ago + seconds ago + diff --git a/translations/messages+intl-icu.eo.xlf b/translations/messages+intl-icu.eo.xlf index 22c47ad..f3109f7 100644 --- a/translations/messages+intl-icu.eo.xlf +++ b/translations/messages+intl-icu.eo.xlf @@ -693,6 +693,30 @@ seconds ago seconds ago + + years ago + years ago + + + months ago + months ago + + + days ago + days ago + + + hours ago + hours ago + + + minutes ago + minutes ago + + + seconds ago + seconds ago + diff --git a/translations/messages+intl-icu.es.xlf b/translations/messages+intl-icu.es.xlf index a134173..8214c8d 100644 --- a/translations/messages+intl-icu.es.xlf +++ b/translations/messages+intl-icu.es.xlf @@ -693,6 +693,30 @@ seconds ago seconds ago + + years ago + years ago + + + months ago + months ago + + + days ago + days ago + + + hours ago + hours ago + + + minutes ago + minutes ago + + + seconds ago + seconds ago + diff --git a/translations/messages+intl-icu.fr.xlf b/translations/messages+intl-icu.fr.xlf index d1dbedb..a9ceeed 100644 --- a/translations/messages+intl-icu.fr.xlf +++ b/translations/messages+intl-icu.fr.xlf @@ -693,6 +693,30 @@ seconds ago seconds ago + + years ago + years ago + + + months ago + months ago + + + days ago + days ago + + + hours ago + hours ago + + + minutes ago + minutes ago + + + seconds ago + seconds ago + diff --git a/translations/messages+intl-icu.he.xlf b/translations/messages+intl-icu.he.xlf index 55a8c0d..57093c5 100644 --- a/translations/messages+intl-icu.he.xlf +++ b/translations/messages+intl-icu.he.xlf @@ -693,6 +693,30 @@ seconds ago seconds ago + + years ago + years ago + + + months ago + months ago + + + days ago + days ago + + + hours ago + hours ago + + + minutes ago + minutes ago + + + seconds ago + seconds ago + diff --git a/translations/messages+intl-icu.it.xlf b/translations/messages+intl-icu.it.xlf index 717e893..40c0271 100644 --- a/translations/messages+intl-icu.it.xlf +++ b/translations/messages+intl-icu.it.xlf @@ -693,6 +693,30 @@ seconds ago seconds ago + + years ago + years ago + + + months ago + months ago + + + days ago + days ago + + + hours ago + hours ago + + + minutes ago + minutes ago + + + seconds ago + seconds ago + diff --git a/translations/messages+intl-icu.ka.xlf b/translations/messages+intl-icu.ka.xlf index 8986d66..9d4e4c3 100644 --- a/translations/messages+intl-icu.ka.xlf +++ b/translations/messages+intl-icu.ka.xlf @@ -693,6 +693,30 @@ seconds ago seconds ago + + years ago + years ago + + + months ago + months ago + + + days ago + days ago + + + hours ago + hours ago + + + minutes ago + minutes ago + + + seconds ago + seconds ago + diff --git a/translations/messages+intl-icu.lv.xlf b/translations/messages+intl-icu.lv.xlf index 898de96..4077e03 100644 --- a/translations/messages+intl-icu.lv.xlf +++ b/translations/messages+intl-icu.lv.xlf @@ -693,6 +693,30 @@ seconds ago seconds ago + + years ago + years ago + + + months ago + months ago + + + days ago + days ago + + + hours ago + hours ago + + + minutes ago + minutes ago + + + seconds ago + seconds ago + diff --git a/translations/messages+intl-icu.pl.xlf b/translations/messages+intl-icu.pl.xlf index d901ba2..98a947a 100644 --- a/translations/messages+intl-icu.pl.xlf +++ b/translations/messages+intl-icu.pl.xlf @@ -693,6 +693,30 @@ seconds ago seconds ago + + years ago + years ago + + + months ago + months ago + + + days ago + days ago + + + hours ago + hours ago + + + minutes ago + minutes ago + + + seconds ago + seconds ago + diff --git a/translations/messages+intl-icu.pt.xlf b/translations/messages+intl-icu.pt.xlf index 71b3a04..e0d5cf7 100644 --- a/translations/messages+intl-icu.pt.xlf +++ b/translations/messages+intl-icu.pt.xlf @@ -693,6 +693,30 @@ seconds ago seconds ago + + years ago + years ago + + + months ago + months ago + + + days ago + days ago + + + hours ago + hours ago + + + minutes ago + minutes ago + + + seconds ago + seconds ago + diff --git a/translations/messages+intl-icu.ru.xlf b/translations/messages+intl-icu.ru.xlf index 24642b6..23e3246 100644 --- a/translations/messages+intl-icu.ru.xlf +++ b/translations/messages+intl-icu.ru.xlf @@ -693,6 +693,30 @@ seconds ago seconds ago + + years ago + years ago + + + months ago + months ago + + + days ago + days ago + + + hours ago + hours ago + + + minutes ago + minutes ago + + + seconds ago + seconds ago + diff --git a/translations/messages+intl-icu.uk.xlf b/translations/messages+intl-icu.uk.xlf index e02bdc1..6b65887 100644 --- a/translations/messages+intl-icu.uk.xlf +++ b/translations/messages+intl-icu.uk.xlf @@ -693,6 +693,30 @@ seconds ago секунд тому + + years ago + years ago + + + months ago + months ago + + + days ago + days ago + + + hours ago + hours ago + + + minutes ago + minutes ago + + + seconds ago + seconds ago +