Not able to output localized dates in twig

Hi, I can’t get to output dates localized (for example when using the full month name). I have tried both the |date() filter, as well as the plugin Twig Extensions which enables |strftime() filter. It always outputs in English. I’m using OC3.1.28 and the main site is set to Spanish locale. The config is set also to ‘es’ locale in the .env file.
Can anybody help me to get this working? I think there should be an easy way (that I can’t find)

Hey @federico.schafer

Try using the carbon() Twig function:

This function should translate and convert to the current site definition.

Hi @daftspunky . Already tried it, but the month names are always showed in English, even thought the primary site is set to Spanish locale (es)

Can you share the code that you are using so we can test it? To prepare a test date just use {{ carbon('now') }}

@daftspunky
In my model (post) I have a date column called ‘published_at’. I get the record in the php block of a page called ‘single-post’, with this code:

<?php
use Vox\Blog\Models\Post;
function onStart(){
   $this['post'] = Post::where('slug', $this->param('slug'))->first();
}
function onEnd(){
   $this->page->title = $this['post']->title;
}
?>

and in my markup block I output the date like this:

{{ carbon(post.published_at).formatLocalized('%d de %B, %Y') }}

The month name (%B) is output in English, no matter that the primary site (only one) is set to spanish locale. The same happens if, with that test date, I use:

{{ carbon('now').formatLocalized('%d de %B, %Y') }}

Hi @federico.schafer

It seems to be working, but the format you gave may not be right. Here is the output I get when setting the locale to es:

carbon('now').formatLocalized('%d de %B, %Y') → 25 de January, 2023

carbon('yesterday').diffForHumans() → hace 1 día

Hi @daftspunky, the format was right. In fact the capital B means the full month name and it appeared in English no matter what. Tried different formats, always returning in English. It’s strange. Maybe some server setting getting in the middle?

Yes, it could be a plugin or some other thing interfering. Try it with a vanilla installation of October CMS.