Translate date

I use a kind of hacky way to convert the user locale (defined with 2 letters, like `fr`) into a local with 5 letters (like `fr_FR`). I guess it should work on most of the case..
This commit is contained in:
Jeremy Benoist 2016-10-20 21:16:01 +02:00
parent 166e8cc6a9
commit 576d285ddf
No known key found for this signature in database
GPG key ID: BCA73962457ACC3C

View file

@ -138,8 +138,11 @@ class WallabagExtension extends \Twig_Extension implements \Twig_Extension_Globa
$interval = $user->getCreatedAt()->diff(new \DateTime('now'));
$nbDays = (int) $interval->format('%a') ?: 1;
// force setlocale for date translation
setlocale(LC_TIME, strtolower($user->getConfig()->getLanguage()).'_'.strtoupper(strtolower($user->getConfig()->getLanguage())));
return $this->translator->trans('footer.stats', [
'%user_creation%' => $user->getCreatedAt()->format('F jS, Y'),
'%user_creation%' => strftime('%e %B %Y', $user->getCreatedAt()->getTimestamp()),
'%nb_archives%' => $nbArchives,
'%per_day%' => round($nbArchives / $nbDays, 2),
]);