-
Notifications
You must be signed in to change notification settings - Fork 164
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
Default locale should be the clients locale and not the servers locale #15947
Comments
You cannot assume that the browser locale is the same as the user's locale. It's more likely that a consistent user experience is achieved if the locale is the same for all users. See #12203 (comment) for more discussion on that topic. At the same time, I agree that it it would be good to have an easier way for the application to opt in to use the browser locale. |
That is true, but if I provide an I18NProvider then it is assumed that the browser locale is the same as the user's locale. So at least it is inconsistent behaviour |
To sum up the inconsistent default behaviour:
IMHO most developers would expect the browsers locale to be the default locale and most ops would not expect the ui to change when they change the servers locale. Having to reset the locale via a VaadinServiceInitListener or providing an I18NProvider with all possible locales is advanced and too much work to achieve such behaviour. |
I think the current system makes things very consistent: only pick from locales that the application supports. Even when there's no I18NProvider, the application implicitly supports a specific language/locale - a locale that might not match the current system's locale. So maybe a configurable default locale would make sense here? This would even be useful with an Btw, DatePicker and DateTimePicker - like all other Components - have the same default behavior: Use the UI's locale if set (based on provided locales and browser locale); otherwise use first locale of I18NProvider. |
I suppose that most or at least many applications would like to support all locales, even if they don't support multiple or all languages. This behavior is currently not supported and would not be supported by a cofigurable default locale either (unless one can configure the default locale to be the browsers locale). e.g. my customer is in aero industy, they communicate in English with worldwide customers (of different/unknown nationalities / languages), so their application is purely in English. But when it comes to enter or display numbers, thir users expect them to be according to their users locale - so e.g "1,00" for german speaking users and "1.00" for english speaking users. The enter numbers via the numeric keyboard, which on a german keyboard has a "," where an english keyboard has a ".". |
Hmm, then Vaadin would need two separate locales. Basically in the same way that Java itself can have a default DISPLAY locale (for the text) that can be different from the default FORMAT locale. |
That would be correct, if ones assumes that a user willingly wants the DISPLAY locale to be different from the FORMAT locale. I don't think that will ever be the case:
|
My claim is that the format locale should by default be the same as the (implicit) display locale. That's the only way of having an application that is deterministic and consistent. There's still room for Vaadin to make things easier for application developers. There should be an easy way for the application to override the server locale (e.g. for the cases where it's shared between multiple applications) and there should also be an easy way for the application to opt in to using the browser locale. |
+1 for that
What do you mean by "(implicit) display locale". What if the servers locale is en-US, the application is in German (no I18NProvider, no translation) and the browsers locale is fi-FI? There is no way to ensure consistency between display and format locale. But we need a deterministic and consistent way to determine the default locale. Right now this is not consistent (see my 3rd post). The only way to make that consistent would be to have the browsers locale as default:
|
Correction to your 3rd post: The server locale is only used when BUT I can see a use case where e.g. you would want to use the date and number format of the browser locale, regardless of the displayed language. Currently, if your application does not have an But that's just my 2 cents. I don't make the decisions around here ;) |
That is correct - I've corrected my post. Unfortunately this makes things even less consistent:
I am not sure how this could work - how to force the developer to explicitly configure a default locale. And even if that could work, wouldn't it contradict the concept of "default"? To sum it up: We need a better way to implicitly or easily explicitly set the locale (without explicitly setting it via a Since I cannot think of a situation, when the servers locale should determine the locale I would suggest:
|
My Spring-based library automatically picks up all available locales (based on the found resource bundles) during startup. And the application's default locale can be any one of them. It can be chosen implicitly based on the system locale (this is basically the default way to choose a default locale...) or explicitly via property. All this is logged so it's easy to see what's going on. In both cases, if there is no match in the available locales, there's a helpful error during startup with info on how to fix it. |
Ok - that works for spring but can't be set (per default) to the browsers locale. We need a simple way to overwrite the UI locale (that is per default the servers-locale) with a specific locale or the browsers locale.
That is something I have never cared of. Have never developed an application with formatted output - results were usually displayed in read-only text fields. But of course, this might be the case. We could ask ourselves the following question:
If so, then the default servers locale leading to "wrong locale, even if consistent to wrongly formatted output" is a much more frequent and painful error than a default browsers locale would lead to "correct input locale, but inconsistent wrongly formatted output". That is why I would opt in for default browsers locale. But of course, if we get an easy and documented functionality to set this, that would be an improvement to the current situation, using the (undocumented) VaadinServiceInitListener technique. |
Describe your motivation
Default locale should be the users locale. This is even written in the documentation (see e.g. "By default, Date Picker displays and parses dates using the user’s locale"). Unfortunately this works only for the locales provided by an I18NProvider. If no I18NProvider is available, the servers locale is used.
Many applications don't need I18N but still want to display fields based on the users locale. They are forced to implement an I18NProvider and guess all possible locales the users might be using, falling back to the servers locale if the guess is wrong.
Describe the solution you'd like
The default locale should be the users locale even if no I18NProvider is available - i.e. same functionality as if an I18NProvider was given without translations but all possible locales provided.
Describe alternatives you've considered
Getting the locale from VaadinRequest.getCurrent().getLocale() and setting it (e.g. in a VaadinServiceInitListener) as proposed in https://discord.com/channels/732335336448852018/1075373133290283189 - a possible workaround
Additional context
According to Frettman the workaround works (I've not tested it), so a similar request mentioned in discord (#5377) is probably fixed and can be closed.
The text was updated successfully, but these errors were encountered: