Skip to content
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

LocaleContextHolder default value should be customizable [SPR-15017] #19584

Closed
spring-projects-issues opened this issue Dec 14, 2016 · 4 comments
Closed
Assignees
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Dec 14, 2016

Louis-Rémi opened SPR-15017 and commented

LocaleContextHolder#getLocale fallbacks on Locale.getDefault() and it may not be the expected result.

The obvious use case is when default application locale is different of JVM's default locale.

Example:
The "application default locale" has "en" as the default locale and jvm is running with "en_US" as the default locale.
The expected result would be to return "en" to be consistent with the rest of the application.


No further details from SPR-15017

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Dec 14, 2016

Juergen Hoeller commented

Which kind of scenario do you have in mind here? Non-web requests, or web requests not going through DispatcherServlet? In general, you could implement a filter or the like, setting a default LocaleContext for such operations...

You could also call Locale.setDefault and adapt the default locale at the JVM level. I suppose you're not doing that since you're in a shared application server environment? We could provide a static LocaleContextHolder.setDefaultLocale method with a locally managed default locale, isolating the default per application as long as the Spring jars are deployed with each application.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Dec 14, 2016

Louis-Rémi commented

Thanks for the quick response.

The use case is to retrieve an always valid locale value from LocaleContextHolder.getLocale() in all cases. For web request, which is already handled by DispatcherServlet, as well as scheduled threads, executor threads, etc.
In our case, it comes from the limitation that the jvm's default locale on which the application is deployed cannot be changed.

I find interesting the LocaleContextHolder.setDefaultLocale, which would resolve our issue.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Dec 14, 2016

Juergen Hoeller commented

Alright, I've added corresponding setDefaultLocale and setDefaultTimeZone methods to LocaleContextHolder. To be backported to 4.3.5.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Dec 15, 2016

Louis-Rémi commented

Much appreciated. Thanks for the backport to 4.3.5 that is soon to be released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.