kalkih / mini-graph-card

Minimalistic graph card for Home Assistant Lovelace UI
MIT License
2.97k stars 232 forks source link

Feature request: define custom locale for formatting (e.g. dot vs comma separation) #702

Open fi-sch opened 2 years ago

fi-sch commented 2 years ago

v0.11.0 introduced change when it comes to number formatting. I personally don't like using commas instead of dots on graphs and similar visualisations (in opposite to what my language setting it pushing on me).

Having that said, for me personally, this change somehow unwanted. That is why I would like to request a feature allowing user to select number formatting of his/her choice. Or maybe somehow better solution: follow settings for particular user.

From what I see, when I changed number formatting in my user's preferences, mini-graph-card was not affected by this setting, while formatting on all other cards changed as intended. With current implementation there still can be a misalignment between user's settings and mini-graph-card.

Thanks for your work guys!

jlsjonas commented 2 years ago

Hi, this was actually a new feature (#495) following changes to HA's frontend (https://github.com/home-assistant/frontend/pull/7516); I confirmed that we are directly using the language data received from HA (main.js:698)

From what I see, when I changed number formatting in my user's preferences, mini-graph-card was not affected by this setting, while formatting on all other cards changed as intended.

Please ensure you cleared your mini-graph-card cache after changing your preferences (adding cache: false to the card could help to investigate)

fi-sch commented 2 years ago

Hi, this was actually a new feature (#495) following changes to HA's frontend (home-assistant/frontend#7516); I confirmed that we are directly using the language data received from HA (main.js:698)

This change forces user to use whatever number formating is "default" for his language. This is not exactly what I requested. My request is to add ability (new card parameter) to set number formatting for each card instance.

Please ensure you cleared your mini-graph-card cache after changing your preferences (adding cache: false to the card could help to investigate)

Just tried cache: false and mini-graph-card still shows commas. Please note that I didn't change the language, I changed the number formatting setting in HA user's preferences. So HA by default sets formatting to appropriate one based on user's language setting. However, you can change this default setting to any other formatting in user's preferences. That is what I did and it changed formatting on every card, except mini-graph-card.

Zrzut ekranu 2022-01-23 o 19 05 41
jlsjonas commented 2 years ago

@fi-sch thanks for the clarification, and sorry for the confusion. I meant that in 0.11 we introduced listening to the set locale.

I was unaware of that custom setting; but it sadly enough also seems that HA used a custom implementation instead of standards to define this parameter (comma_decimal, ...; instead of a country-code) locale: Object { language: "en-GB", number_format: "comma_decimal", time_format: "language" }

We could add a locale override config parameter to define this on your card.

If anyone has a better approach that would allow us to (cleanly) use the locale.number_format from HA after all, suggestions are welcome! going to introduce custom card helper to handle this & some other functionality

fi-sch commented 2 years ago

@jlsjonas No worries, thanks for helping.

I guess I won't be much helpful here as I'm not a developer. Anyways, I'm glad that my issue made any sense to you :) Thanks

ildar170975 commented 2 years ago

Tested again (HA2022.7.2). The card does not follow user's locale. I changed a "number's format". Cleared a cache after every change. Chrome, Edge - same. image

jlsjonas commented 2 years ago

@ildar170975 As expected, we didn't have an opportunity to include the solutions mentioned in https://github.com/kalkih/mini-graph-card/issues/702#issuecomment-1019543164.

ildar170975 commented 2 years ago

@jlsjonas It is OK, at least we documented our proposals/conclusions here...

metawops commented 1 year ago

I just stumbled upon a similar problem: the time format is always 12h format (with am & pm) – not reflecting my user setting of 24h format. I checked with cache: false and reloaded the dashboard page – same result: still 12h format.

ildar170975 commented 1 year ago

@metawops Check docs for the “hour24” option.

howi42 commented 1 year ago

It does follow the user settings for locale, but incorrectly. Example : When changing from 'english' to 'deutsch',
numbers change from '1,000.34' to '1.000,34' . It should be '1000,34' , i.e. following the 'number format' from the user settings