Skip to content

Commit 8be5010

Browse files
committed
LocaleEditor supports BCP 47 language tags as well
Closes gh-33348
1 parent 86761cd commit 8be5010

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

spring-beans/src/main/java/org/springframework/beans/propertyeditors/LocaleEditor.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -30,13 +30,13 @@
3030
* @author Juergen Hoeller
3131
* @since 26.05.2003
3232
* @see java.util.Locale
33-
* @see org.springframework.util.StringUtils#parseLocaleString
33+
* @see org.springframework.util.StringUtils#parseLocale
3434
*/
3535
public class LocaleEditor extends PropertyEditorSupport {
3636

3737
@Override
3838
public void setAsText(String text) {
39-
setValue(StringUtils.parseLocaleString(text));
39+
setValue(StringUtils.parseLocale(text));
4040
}
4141

4242
@Override

spring-beans/src/test/java/org/springframework/beans/propertyeditors/CustomEditorTests.java

+4
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,10 @@ void localeEditor() {
648648
assertThat(localeEditor.getValue()).isEqualTo(Locale.CANADA);
649649
assertThat(localeEditor.getAsText()).isEqualTo("en_CA");
650650

651+
localeEditor = new LocaleEditor();
652+
localeEditor.setAsText("zh-Hans");
653+
assertThat(localeEditor.getValue()).isEqualTo(Locale.forLanguageTag("zh-Hans"));
654+
651655
localeEditor = new LocaleEditor();
652656
assertThat(localeEditor.getAsText()).isEmpty();
653657
}

0 commit comments

Comments
 (0)