Localisation fix

Hi,

My Home Assistant language is “Nederlands” but all the days, week, months etc etc are in English.
When I’m using {{ now().strftime('%A') }} the result is Sunday instead of Zondag

It would be nice that localisation is used for the selected language.

How would that work with templates like this {{ now().strftime('%A') == 'Monday' }}
It could be true if the language is set to English, but would always be false if the language is Dutch.

Furthermore, the language is set on user level, and that is only known in the frontend. And multiple users can have different languages set. I use English myself, but my girlfriend uses Dutch. Which language should be used to render the template above?

1 Like

It should be possible to use a different language on the frontend only.

That is possible right now, you can set the preferenced language on your profile settings.

But templates don’t use these profile settings. If you would have 5 user accounts in your HA server, using 5 different languages in their profile, which language should be used to render the template then?

Keep English for the backup/template/automations but use the local settings on the frontend only. When a user has selected another language instead of English it should be system-wide, including days/months etc.

1 Like

@petro would something like this be possible?

In the frontend the variable user_language would be made available.
Then timestamp_custom() would get an additional setting use_locale.
Then this would be possible to use in the
frontend:

{{ now().timestamp() | timestamp_custom('%A', use_locale=user_language) }}
3 Likes

Hi @thefes, does this problem has eventually been solved? Or does it have a simple solution?
I’m new to HA, but I’m facing the same issue than @evertjob.
The code {{ now().strftime('%A %d %B')) }} keeps giving words in english, despite my locale correctly set in the user profile GUI.
I’ve red that there is a function as_local() provided (Templating - Home Assistant)
But it seems that as_local() is more used to convert time into local timezone. Rather than convert days or months into local user language.
Thus, something should work inside HA, because, for example, the Wheather Forecast card is able to show days and type of weather (cloudy, sunny, etc) in the correct set language, without doing any special settings (I’ve changed the language in my profile to verify).
I’ve seen some scripting workarounds where we have to code ourselves a conversion of days and months, but… hum… pff… :face_with_raised_eyebrow:

1 Like

There is no other solution besides providing the translation yourself in the template.

I don’t know how I missed this @. No something like that would not be possible as templates are rendered in the backend and they are rendered without the frontend even knowing they were rendered. The only possible way to support this is to do what we currently do: Output datetimes on a device_class. We could possibly add a new device_class with a new field or attribute that contains the format. Then the frontend would render the datetime with the associated format in the user defined language.

This will never be solved in the backend by what thefes highlighted above. This can only be solved in the frontend. See previous response. I understand it’s frustrating, but it’s just not possible to fix inside the templates. So rather than focus on the template being the issue, we should focus on a solution that works for the frontend.

My post got another :heart: so I reread your reply now.

I meant specifically for usage in templates in the frontend (eg a markdown card or mushroom template card).

timestamp_custom() would have an additional language parameter, you could then use a string like "nl" but specifically in templates used in the frontend (in the cards mentioned above) a user_language variable could be used.

But I guess timestamp_custom uses strftime. So I don’t think it would be possible