Date not visual in local language

I do not understand why I cannot get the months in the local language.

{{as_timestamp(states(“input_datetime.deurbelknoptijddatum”))|timestamp_custom("%d %B %Y %X", local=true) }}

Result: 16 May 2023 00:02:05
I like to see: 16 mei 2023 00:02:05

Despite to the user’s locale is set to the local language, day and month are displayed in English.

Shouldn’t it follow the locale setting as well?

It should but doesn’t:

See here also:

System-technically it seems very simple to me. Months are displayed by default with a number. This number can be converted to the month in the local language.

Strange that such a basic thing is not available in Home Assistant.

The frontend is where the user selects their desired presentation language but templates are processed by the backend. The frontend has no knowledge of the timestamp_custom filter or any other Jinja2 filter.

For more information, refer to petro’s post.

The backend of the software has no concept of ‘language’. Templates are built into the backend. The frontend also has multiple users with multiple languages. So how would a single template sensor render into multiple different languages in the backend if the template sensor is a single value? It can’t. So, the only option is to have this render in the frontend, where the translations occur per user. Meaning, you can’t do it in the template sensor.

{% set i,t = states('input_datetime.deurbelknoptijddatum').split() %}
{% set y,m,d = i.split('-')|map('int') %}
{{ '%d %s %d %s' % (d, ['jan.','feb.','mrt.','apr.','mei','juni','juli','aug.','sep.','okt.','nov.','dec.'][m-1], y, t) }}

EDIT: off-by-one error fixed!

1 Like

Thanks, this helps a lot. :slight_smile:
I made a small change to it because the month says juni. To correct this I changed it to [m-1]

{% set i,t = states('input_datetime.deurbelknoptijddatum').split() %}
{% set y,m,d = i.split('-')|map('int') %}
{{ '%d %s %d %s' % (d, ['jan','feb','mrt','apr','mei','jun','jul','aug','sep','okt','nov','dec'][m-1], y, t) }}

One-liner (split for the forum) for long month names:

{{ as_timestamp(states("input_datetime.deurbelknoptijddatum"))
   |timestamp_custom("%d %B %Y %X", local=true)
   |lower  
   |replace('y','i')
   |replace('rch','art')
   |replace('ai','ei')
   |replace('ne','ni')
   |replace('st','stus')
   |replace('ct','kt') }}
1 Like

@Troon
The second option is a clever one. :wink:I have integrated the 1st option and this works perfect for me. :partying_face:
Thanks for your help.

@petro But even the frontend does not know about the language to use, it seems. Create a markdown card in the frontend and use this, {{ now().strftime(“%A %H:%M”) }} as the text. Weekday is in english, regardless of the language used in the frontend.

The frontend uses the templating from the backend. No templates will have transitions

Yes, and this is by design. I am not saying this is good or bad design, but it is in the frontend and according to your post, the frontend knows or should know about the current users language.

But it is like it is and nothing to do about it at the moment. And I can only hope that the markdown card gets enough priority to be fixed sometime in the future.

And regarding the system language. There is a setting for this in HA and the smart thing to do, is to use this setting for languages in the backend. What else should this setting be used for?

And the new Holiday integration introduced in 2024.1 is using this language setting when creating the holiday calendar. Thumbs up for that. So it is in fact possible to find a solution for this and I don’t think it is difficult either, as the holiday integration has shown.

It does. But that’s only available in JS templates if exposed to the js template engine. Iirc custom button card has this, which is why I mentioned it before.

Please help :wink: i`m to bad

Ich have a timestamp sensor and i would it display in german language.
this is the sensor:

{{ as_timestamp(states('sensor.start_appliance_awattar')) | timestamp_custom('%d. %b %Y, %H:%M Uhr' ) }}

It displays: 03. Mar 2024, 14:00 Uhr

How can i do this. I’ve read a lot of forums and posts, but unfortunately I haven’t found a solution.

Thanks a lot

{% from 'easy_time.jinja' import month %}
# there might be a quicker way to get the moth number,
# depending on the format of the sensor state:
{% set mn = (as_timestamp(states('sensor.start_appliance_awattar'))
            |as_datetime).month %}
{{ (as_timestamp(states('sensor.start_appliance_awattar'))
   |timestamp_custom('%d. X %Y, %H:%M Uhr'))
   .replace('X', month(mn)) }}