LocaleEditor supports BCP 47 language tags as well
Closes gh-33348
This commit is contained in:
parent
86761cd233
commit
8be5010f5d
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2021 the original author or authors.
|
* Copyright 2002-2024 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -30,13 +30,13 @@ import org.springframework.util.StringUtils;
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
* @since 26.05.2003
|
* @since 26.05.2003
|
||||||
* @see java.util.Locale
|
* @see java.util.Locale
|
||||||
* @see org.springframework.util.StringUtils#parseLocaleString
|
* @see org.springframework.util.StringUtils#parseLocale
|
||||||
*/
|
*/
|
||||||
public class LocaleEditor extends PropertyEditorSupport {
|
public class LocaleEditor extends PropertyEditorSupport {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setAsText(String text) {
|
public void setAsText(String text) {
|
||||||
setValue(StringUtils.parseLocaleString(text));
|
setValue(StringUtils.parseLocale(text));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -648,6 +648,10 @@ class CustomEditorTests {
|
||||||
assertThat(localeEditor.getValue()).isEqualTo(Locale.CANADA);
|
assertThat(localeEditor.getValue()).isEqualTo(Locale.CANADA);
|
||||||
assertThat(localeEditor.getAsText()).isEqualTo("en_CA");
|
assertThat(localeEditor.getAsText()).isEqualTo("en_CA");
|
||||||
|
|
||||||
|
localeEditor = new LocaleEditor();
|
||||||
|
localeEditor.setAsText("zh-Hans");
|
||||||
|
assertThat(localeEditor.getValue()).isEqualTo(Locale.forLanguageTag("zh-Hans"));
|
||||||
|
|
||||||
localeEditor = new LocaleEditor();
|
localeEditor = new LocaleEditor();
|
||||||
assertThat(localeEditor.getAsText()).isEmpty();
|
assertThat(localeEditor.getAsText()).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue