Day and month does not follow locale setting

Hello,
In a markdown card I’ve got:

{{ as_timestamp(state_attr('automation.dz_584', 'last_triggered')) | timestamp_custom('%A %d %B %Y à %-H:%M') }} 

Despite the user’s locale is set to french, day and month are displayed in english. Shouldn’it follow the locale setting?
Is there a known workaround?
Thank you

To my knowledge, all functions of the Jinja2 templating language (and python) default to English (and don’t adapt to the operating system’s locale setting).

Your template will need to use mapping to translate ordinal day/month values to day/month names.

{{ "%s %d %s %d à %02d:%d" %
   (["Lundi","Mardi","Mercredi","Jeudi","Vendredi","Samedi","Dimanche"][now().weekday()],
   now().day,
   ["Janvier","Fevrier","Mars","Avril","Mai","Juin","Juillet","Aout","Septembre","Octobre","Novembre","Decembre"][now().month-1],
   now().year,
   now().hour,
   now().minute) }}

Example

1 Like

Thank you so much I did not know the mapping function, pretty powerfull. This is the code I ended with. However I could not make it more compact by using only one formating instruction like you did in the example above.

{{ "%s" %
  (["Lundi","Mardi","Mercredi","Jeudi","Vendredi","Samedi","Dimanche"][as_timestamp(state_attr('automation.dz_584', 'last_triggered')) | timestamp_custom( '%w') | int ]
) 
}} {{ 
as_timestamp(state_attr('automation.dz_584', 'last_triggered')) | timestamp_custom( '%d')
}} {{ "%s" % 
["Janvier","Février","Mars","Avril","Mai","Juin","Juillet","Août","Septembre","Octobre","Novembre","Décembre"][as_timestamp(state_attr('automation.dz_584', 'last_triggered')) | timestamp_custom( '%m') | int -1]
}} {{ 
as_timestamp(state_attr('automation.dz_584', 'last_triggered')) | timestamp_custom('à %-H:%M') 
}} 
{% set t = state_attr('automation.dz_584', 'last_triggered') %}
{{ "%s %d %s à %02d:%02d" %
   (["Lundi","Mardi","Mercredi","Jeudi","Vendredi","Samedi","Dimanche"][t.weekday()],
   t.day,
   ["Janvier","Fevrier","Mars","Avril","Mai","Juin","Juillet","Aout","Septembre","Octobre","Novembre","Decembre"][t.month-1],
   t.hour,
   t.minute) }}

of course, brilliant thank you.
Edit: need to add +1 to t.weekday() to get the correct day

That’s odd because now().weekday() reports an integer value ranging from 0 to 6 where 0 is Monday (Lundi) and 6 is Sunday (Dimanche). Today is Tuesday (Mardi) so it reports 1 which corresponds to the the second item in the list (because lists are indexed from zero). The second element is Mardi.

my bad I’m very sorry, you are correct. I thought we were Wednesday so my mistake!
Cheers