flow
flow copied to clipboard
Language preference updates in browser are not recognized upon a forced refresh
Description of the bug
When I change my browser language (e.g. through Chrome developer tools) and refresh the page, the translated text strings are not updated. If I log out the current user (or delete cookies), the language is changed.
Expected behavior
I would expect that the accepted browser languages are respected whenever a page is refreshed.
Minimal reproducible example
See https://github.com/vaadin/bakery-app-starter-flow-spring (tag cc-24.8).
- Run the application (with no maven profiles selected)
- On the login screen, use Chrome Developer Tools > Sensors to change the locale to
es(Spanish). - Refresh the screen and note that the language doesn't change.
- Delete cookies.
- Refresh the screen and note that the language DOES change.
Versions
- Vaadin / Flow version: 24.8
- Java version: OpenJDK 23
- OS version: Windows 11
- Browser version (if applicable): Chrome 137.0.7151.69
- Application Server (if applicable): Tomcat 10.1.41
- IDE (if applicable): N/A
[Internal]: See https://github.com/vaadin/control-center/issues/904
The session locale is populated once when the session is created which leads to exactly the behavior that you describe. Could make sense to re-check the browser preferences every time an new UI instance is inited.
We should probably better do the locale settings update in UI init as a opt-in feature. Otherwise what is set during the session init may be overridden by what is in UI init, that may be unexpected. Or we can just document how to re-set the locale on each UI init.
Also I'm not really sure how to treat this - bug or feature.
I would say feature as the current session-based strategy is working as it was intended to.
Either introducing documentation or providing the option for a UI-based strategy would both be improvements rather than fixes.