Skip to content

Simplify default locale/timezone resolution in cookie/session locale resolvers #27609

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

Closed
wants to merge 3 commits into from

Conversation

vpavic
Copy link
Contributor

@vpavic vpavic commented Oct 25, 2021

At present, the customization of the default locale and timezone resolution in CookieLocaleResolver and SessionLocaleResolver requires subclassing them and overriding determineDefaultLocale and/or determineDefaultTimeZone methods.

This PR simplifies resolution of the default locale and timezone resolution by introducing dedicated functions for these purposes, thus allowing the customization without needing to resort to subclassing the locale resolvers.

Additionally, there are also 2 small commits that improve some aspects of the LocaleResolver hierarchy:

  • Update AcceptHeaderLocaleResolver to extend AbstractLocaleResolver:
    This commit updates AcceptHeaderLocaleResolver to extend AbstractLocaleResolver, which allows the removal of defaultLocale managing code in AcceptHeaderLocaleResolver.

  • Update LocaleContextResolver to implement LocaleResolver:
    This commit updates LocaleContextResolver to implement LocaleResolver using default methods, which simplifies AbstractLocaleContextResolver and aligns it more closely with AbstractLocaleResolver.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Oct 25, 2021
@sbrannen sbrannen added the in: web Issues in web modules (web, webmvc, webflux, websocket) label Oct 26, 2021
@vpavic vpavic force-pushed the improve-locale-resolvers branch from e520124 to 77ce689 Compare May 30, 2022 10:48
@vpavic
Copy link
Contributor Author

vpavic commented May 30, 2022

Any feedback on this?

@sbrannen sbrannen added the type: enhancement A general enhancement label May 30, 2022
@sbrannen
Copy link
Member

sbrannen commented May 30, 2022

Any feedback on this?

Hi @vpavic,

We just have not gotten to it yet.

We'll review it and hopefully get it into 6.0 M5.

@sbrannen sbrannen removed the status: waiting-for-triage An issue we've not yet triaged or decided on label May 30, 2022
@sbrannen sbrannen self-assigned this May 30, 2022
@sbrannen sbrannen added this to the 6.0.0-M5 milestone May 30, 2022
vpavic added 3 commits May 31, 2022 18:39
This commit updates AcceptHeaderLocaleResolver to extend AbstractLocaleResolver, which allows the removal of defaultLocale managing code in AcceptHeaderLocaleResolver.
This commit updates LocaleContextResolver to implement LocaleResolver using default methods, which simplifies AbstractLocaleContextResolver and aligns it more closely with AbstractLocaleResolver.
…resolvers

At present, the customization of the default locale and timezone resolution in CookieLocaleResolver and SessionLocaleResolver requires subclassing them and overriding determineDefaultLocale and/or determineDefaultTimeZone methods.

This commit simplifies resolution of the default locale and timezone resolution by introducing dedicated functions for these purposes, thus allowing the customization without needing to resort to subclassing the locale resolvers.
@vpavic
Copy link
Contributor Author

vpavic commented May 31, 2022

Thanks @sbrannen.

In my notes I had a few other improvement proposals that weren't as straightforward as those included in this PR:

  • refactor CookieLocaleResolver to extend AbstractLocaleContextResolver, and delegate to CookieGenerator instead of extending it - this would eliminate some duplication but would also introduce some breaking changes (that are IMO welcome as CookieLocaleResolver doesn't really need many of the methods it inherits from the CookieGenerator and would also really need a constructor that takes cookie name).
  • introduce AcceptHeaderLocaleContextResolver that would replace AcceptHeaderLocaleResolver and align with reactive side (which offers org.springframework.web.server.i18n.AcceptHeaderLocaleContextResolver) - that would also open the path for deprecating org.springframework.web.servlet.LocaleResolver.

Anyway, let me know what you think of those and I can either add commits to this PR or open separate issues (or PRs) to consider those separately. IMO the whole LocaleResolver hierarchy could use some modernization and chances to do so (that is, new major releases) don't come too often.

@vpavic vpavic force-pushed the improve-locale-resolvers branch from 77ce689 to d6bee29 Compare May 31, 2022 17:31
@sbrannen
Copy link
Member

sbrannen commented Jun 2, 2022

Anyway, let me know what you think of those and I can either add commits to this PR or open separate issues (or PRs) to consider those separately.

I'll assess that after merging the three commits in this PR.

IMO the whole LocaleResolver hierarchy could use some modernization and chances to do so (that is, new major releases) don't come too often.

Indeed, 6.0 is a good opportunity for "modernization".

sbrannen pushed a commit to sbrannen/spring-framework that referenced this pull request Jun 3, 2022
This commit updates AcceptHeaderLocaleResolver to extend
AbstractLocaleResolver, which allows the removal of defaultLocale
managing code in AcceptHeaderLocaleResolver.

See spring-projectsgh-27609
sbrannen pushed a commit that referenced this pull request Jun 3, 2022
This commit updates LocaleContextResolver to implement LocaleResolver
using default methods, which simplifies AbstractLocaleContextResolver
and aligns it more closely with AbstractLocaleResolver.

See gh-27609
sbrannen added a commit to sbrannen/spring-framework that referenced this pull request Jun 3, 2022
@sbrannen sbrannen closed this in 864dcf6 Jun 3, 2022
@vpavic vpavic deleted the improve-locale-resolvers branch June 3, 2022 13:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants