Skip to content

StringToLocaleConverter should allow BCP 47 values [SPR-16188] #20736

Closed

Description

@spring-projects-issues

adrian opened SPR-16188 and commented

I'm using Spring Boot to setup locale in spring mvc.

I'm trying to use BCP 47 for spring.mvc.locale value, but I end up with a

Property: spring.mvc.locale
Value: en-US
Reason: Failed to convert property value of type 'java.lang.String' to required type 'java.util.Locale' for property 'locale'; nested exception is org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.lang.String] to type [java.util.Locale]

StringToLocaleConverter (relies on StringUtils.parseLocaleString) relies on _ delimiters, which is not BCP 47.

Could StringToLocaleConverter be improved to handle BCP 47 (or otherwise try both formats ?)

For BCP-47, it would correspond to calling
https://docs.oracle.com/javase/7/docs/api/java/util/Locale.html#forLanguageTag(java.lang.String)

wdyt ?


Affects: 4.3.10

Issue Links:

Referenced from: commits ef3f93e

Activity

  1. spring-projects-issues commented on Jan 25, 2018

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    Good point! StringToLocaleConverter leniently supports both variants now, through a new StringUtils.parseLocale variant which adapts to both BCP 47 and the traditional Locale.toString() format.

  2. spring-projects-issues commented on Jan 25, 2018

    @spring-projects-issues
    CollaboratorAuthor

    adrian commented

    Great ! Thanks very much Juergen

  3. added
    type: enhancement
    in: core
    on Jan 11, 2019
  4. added this to the 5.0.4 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: coretype: enhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions