Skip to content

AcceptHeaderLocaleResolver should allow to define a default Locale [SPR-14312] #18884

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
spring-projects-issues opened this issue May 27, 2016 · 4 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented May 27, 2016

Oliver Drotbohm opened SPR-14312 and commented

It would be cool if AcceptHeaderLocaleResolver would allow configuring a default Locale just as CookieLocaleResolver does. The use case is that I'd like to allow clients to explicit request a certain local but at the same time make sure that a well-defined default is used, independently of the system language (to prevent different deployment locations from changing the default).

It looks like we'd have to check whether the Accept-Language header is set explicitly to find out whether to use the configured default in the first place.


Issue Links:

Referenced from: commits 8343ce9

@spring-projects-issues
Copy link
Collaborator Author

Rossen Stoyanchev commented

Oops, Juergen I didn't see you assigned that one already. I had chatted with Ollie about it just before.

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

No worries, I'm happy for it to be picked up for 4.3 GA still. Assigning it to you for the time being :-)

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Apr 10, 2017

Tadas Krivickas commented

The current implementation does not fallback to default locale if the client-requested locale is not supported.
Consider this (currently failing) test case:

    @Test
    public void resolvePreferredNotSupported2() {
        this.resolver.setSupportedLocales(Arrays.asList(US, JAPAN));
        this.resolver.setDefaultLocale(Locale.JAPAN);

        MockHttpServletRequest request = new MockHttpServletRequest();
        request.addHeader("Accept-Language", KOREA.toString());
        request.setPreferredLocales(Collections.singletonList(KOREA));

        assertEquals(Locale.JAPAN, this.resolver.resolveLocale(request));
    }

Shouldn't default locale be used as a fallback?

https://github.com/spring-projects/spring-framework/blob/master/spring-webmvc/src/main/java/org/springframework/web/servlet/i18n/AcceptHeaderLocaleResolver.java#L100

Related: #17915

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Apr 10, 2017

Juergen Hoeller commented

Good point! I've created #19987 to track such a revision.

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

No branches or pull requests

2 participants