Skip to content

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

Closed

Description

@spring-projects-issues

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

Activity

  1. spring-projects-issues commented on May 27, 2016

    @spring-projects-issues
    CollaboratorAuthor

    Rossen Stoyanchev commented

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

  2. spring-projects-issues commented on May 27, 2016

    @spring-projects-issues
    CollaboratorAuthor

    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 :-)

  3. spring-projects-issues commented on Apr 10, 2017

    @spring-projects-issues
    CollaboratorAuthor

    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

  4. spring-projects-issues commented on Apr 10, 2017

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

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

  5. added
    type: enhancement
    in: web
    on Jan 11, 2019
  6. added this to the 4.3 GA milestone on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: webtype: enhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions