alwin said:
Adding this to your Plugin.php file will do (in most cases) the job:
Add this at the top of the Plugin.php file:
use Carbon\Carbon;
use Lang;
Add this to the body of the Plugin class:
/**
* Boot method, called right before the request route.
*/
public function boot()
{
$localeCode = Lang::getLocale();
setlocale(LC_TIME, $localeCode . '_' . strtoupper($localeCode) . '.UTF-8');
}
/**
* Registers CMS markup tags introduced by this plugin.
*/
public function registerMarkupTags()
{
return [
'filters' => [
'strftime' => function(Carbon $time, $format) {
return strftime($format, $time->getTimestamp());
}
]
];
}
In the Twig template:
{{ post.published_at|strftime('%A %e %B %Y') }}
That code us actually not a good general recommendation, as the utf language code (first part before underscore) not always is the same as the country (first part before underscore).
Also no nee to redefine strftime(). Even date() change language format when you set core php value by setlocale().
Easiest is to just add setlocale(LCTIME, "sv'SE.UTF-8");
on config/app.php
If you want to use dynamical translation and change of language by session for frontend, you need yo use the following syntax, and have twig extension installed:
{{ date|localizeddate('full', 'none', defaultLocale, null, 'dd MMMM, yyyy') }}
The problem is that most plugin are not configured for that intl carbon format, so you need to change a lot of twig format in your own partials.
My bee there is an other solution, would bee glad to hear it, though.