Skip to content

Commit 51816e2

Browse files
elPeirettijavier-godoy
authored andcommitted
fix: default to the UI locale instead of jvm default locale
1 parent e24b044 commit 51816e2

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/main/java/com/flowingcode/vaadin/addons/localecombobox/LocaleComboBox.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.vaadin.flow.data.renderer.LitRenderer;
2828
import java.util.Collection;
2929
import java.util.Locale;
30+
import java.util.Optional;
3031

3132
/**
3233
* Vaadin ComboBox extension that allows to choose between multiple locales.
@@ -76,7 +77,7 @@ public enum DisplayMode {
7677
}
7778

7879
private DisplayMode displayMode = DisplayMode.DEFAULT;
79-
private Locale customDisplayLocale = Locale.getDefault();
80+
private Locale customDisplayLocale;
8081

8182
/**
8283
* Indicates whether the flags should be displayed alongside the locale names.
@@ -124,7 +125,7 @@ public void setDisplayMode(DisplayMode displayMode) {
124125
* @param displayLocale the {@code Locale} to use for formatting.
125126
*/
126127
public void setDisplayLocale(Locale displayLocale) {
127-
this.customDisplayLocale = displayLocale == null ? Locale.getDefault() : displayLocale;
128+
this.customDisplayLocale = displayLocale;
128129
}
129130

130131
/**
@@ -178,13 +179,13 @@ private Locale getLocaleForDisplay() {
178179
switch (displayMode) {
179180

180181
case CUSTOM:
181-
return customDisplayLocale;
182+
return Optional.ofNullable(customDisplayLocale).orElseGet(this::getLocale);
182183

183184
case SELECTED:
184-
return this.getValue() == null ? Locale.getDefault() : this.getValue();
185+
return Optional.ofNullable(this.getValue()).orElseGet(this::getLocale);
185186

186187
default:
187-
return Locale.getDefault();
188+
return this.getLocale();
188189
}
189190
}
190191

0 commit comments

Comments
 (0)