Skip to content

Commit a381992

Browse files
committed
setting locale to english on startup. keeping system locale for convertions like date format
1 parent 8d0cd21 commit a381992

File tree

1 file changed

+20
-0
lines changed
  • src/main/java/de/doubleslash/keeptime

1 file changed

+20
-0
lines changed

src/main/java/de/doubleslash/keeptime/App.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.io.StringWriter;
2222
import java.time.LocalDate;
2323
import java.util.List;
24+
import java.util.Locale;
2425
import java.util.Optional;
2526
import java.util.stream.Collectors;
2627

@@ -84,6 +85,9 @@ public class App extends Application {
8485
@Override
8586
public void init() throws Exception {
8687
LOG.info("Starting KeepTime.");
88+
89+
setLocaleToEnglish();
90+
8791
final DefaultExceptionHandler defaultExceptionHandler = new DefaultExceptionHandler();
8892
defaultExceptionHandler.register();
8993

@@ -102,6 +106,22 @@ public void init() throws Exception {
102106
model.setSpringContext(springContext);
103107
}
104108

109+
private void setLocaleToEnglish() {
110+
final Locale systemDefaultLocale = Locale.getDefault();
111+
final Locale wantedApplicationLocale = Locale.ENGLISH;
112+
113+
if(systemDefaultLocale.getLanguage().equals(wantedApplicationLocale.getLanguage())){
114+
LOG.debug("Application Locale already is '{}'. Nothing to do.", wantedApplicationLocale);
115+
return;
116+
}
117+
118+
LOG.info("Setting application Locale to '{}', was '{}'.", wantedApplicationLocale, systemDefaultLocale);
119+
Locale.setDefault(wantedApplicationLocale);
120+
Locale.setDefault(Locale.Category.DISPLAY, wantedApplicationLocale);
121+
// keep system locale for format conversions (date, currency, numbers)
122+
Locale.setDefault(Locale.Category.FORMAT, systemDefaultLocale);
123+
}
124+
105125
@Override
106126
public void start(final Stage primaryStage) {
107127
LOG.info("Initialising the UI");

0 commit comments

Comments
 (0)