Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Arturo's avatar
Level 10

Change date language

Hi, I changed the locale and fallback_locale to 'es' in my config file (laravel 5), and I have parsed my dates with carbon and doesn't change the language

any ideas?

0 likes
8 replies
socieboy's avatar

Tube el mismo problema, supuestamente Carbon tiene ya soporte para lenguajes pero a lo que veo no se basa en la configuracion de laravel para cambiarlo, tienes que indicarle a Carbon que estas en español tambien!

rjsworking's avatar

Hi

Since the app is a L4 app, I did it in a route filter in filters.php

Route::filter('SetLocaleFilter', function()
{
    $locale = LaravelLocalization::getCurrentLocale();
    setlocale(LC_ALL, strtolower($locale) . "_" . strtoupper($locale) . ".utf8");
});
Arturo's avatar
Level 10

I try to put in accessor like this

    public function getNewsDateAttribute()
    {
        setlocale(LC_ALL, 'German');
        return $this->created_at->formatLocalized('%A %d %B %Y');
    }

but doesn't work, always return in english

Arturo's avatar
Level 10

its homestead issue I deploy to my server and works

Thanks

Please or to participate in this conversation.