-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create number formatting options on the profile panel #7925
Create number formatting options on the profile panel #7925
Conversation
I'm not sure if the two options (comma for thousands separator, decimal for thousands separator) make sense. Eg. in Czech we have space for thousands separator. I'm happy user of the auto option (and I thank you very much for the implementation) but I can imagine some users may want to use English language and the Czech number formatting - just like other users for other languages in #7745 So I think the best implementation would be to have two options for decimal point and thousands separator. |
@kukulich thank you for the feedback. I think you are right and I want to enable this feature to handle as many use-cases as possible. I'm going to rework the options a bit, because the current approach starts to get brittle with more and more options. Unfortunately there isn't a good browser localization API where I can arbitrarily specify what to use for the thousands separator and the decimal separator; it has to be a Unicode BCP 47 locale identifier. |
The latest commits add an option for spaces as thousands separators, and a "Use system locale" option that uses the system default locale. This option is probably what most users should choose when they select English as the language but prefer native locale formatting. The commits also add fallback locales for the three specific formatting options in case the first locale is not available on the users browser/operating system. This should ensure that the formatting works as expected in most cases. A "live" formatted number is now in the description to provide quick visual feedback so users can verify the chosen format is working as expected. |
I'm thinking about where we should store these settings, currently, we already store the language per user in the frontend user data under |
I think I agree with Bram that this would be cleaner and just a logical: {
"version": 1,
"key": "frontend.user_data_ca2aa4188cea409b8b281db15bec6072",
"data": {
"language": {
"language": "en",
"number_format": "de"
}
}
} At runtime we then have this one object with all localization info, so we keep lean and clean interfaces 👍 . |
@bramkragten @spacegaier saving the data to the |
Yeah, it would need some refactoring |
7e95e33
to
9ec6d33
Compare
@bramkragten I rebased and force pushed after all of the import sorting in dev. The latest changes include a refactor of the use of |
@bramkragten the latest commits should address all of the comments from your last review. |
Sorry for the delay, I'll look into it this week. Could you rebase and fix the tests? |
4dbbad2
to
85f4187
Compare
@bramkragten rebase is complete and all tests are passing. |
Will this be accessible like the hass language parameter to lovelace cards? |
@JonahKr I have not done any custom lovelace card development, so I'm not familiar with what data or methods are available to custom cards. If the card is using the @bramkragten do you know how this may impact custom lovelace cards? |
I was thinking about that the other day, this will be a breaking change for custom cards, something we should think about. |
5022f9f
to
5299230
Compare
🎉 Thanks @joshmcrty |
@iantrich just FYI... this will Require some changes for the |
@bramkragten Thanks for your patience with all of the reviews, much appreciated! |
Proposed change
This adds a Number Format option to the Profile panel that allows users to select how numbers are formatted in the UI. The available options are Auto (use language), comma for thousands separator, decimal for thousands separator, and none which bypasses the formatting function wherever it is used.
This is implemented by saving the format choice to the core user data. I'm not sure if any core/python changes are required; this seems to work fine in my dev environment with frontend changes only.
This PR updates the
computeStateDisplay
function to use a new argument --hass.userData
-- and updates all areas of the code that call this function to pass in the new argument. I opted for this approach so that in the future if other formatting features are created (for example date format options), they can be saved to the core user data and will already be available tocomputeStateDisplay
without updating all uses ofcomputeStateDisplay
again.The
formatNumber
function is also updated with new expected arguments to allow for format options. All direct uses of theformatNumber
function have been updated.Type of change
Example configuration
Go to the profile page and select a number format. Lovelace dashboards should now display numbers that reflect the selected number format.
Additional information
Checklist
If user exposed functionality or configuration variables are added/changed: