Skip to content

Commit 2d0f68d

Browse files
authored
Merge pull request #191 from doubleSlashde/bugfix/PTBAS-737_consistentLanguage_2
using consistent english language now. keeping dates in system locale
2 parents 9270aec + 7793cf3 commit 2d0f68d

File tree

1 file changed

+23
-2
lines changed
  • src/main/java/de/doubleslash/keeptime

1 file changed

+23
-2
lines changed

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

Lines changed: 23 additions & 2 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");
@@ -117,12 +137,13 @@ public void start(final Stage primaryStage) {
117137
}
118138
}
119139

120-
public static void showErrorDialogAndWait(String title, String header, String content, final Exception e, Window window) {
140+
public static void showErrorDialogAndWait(String title, String header, String content, final Exception e,
141+
Window window) {
121142
final Alert alert = new Alert(AlertType.ERROR);
122143
alert.setTitle(title);
123144
alert.setHeaderText(header);
124145
alert.setContentText(content);
125-
if(window != null) {
146+
if (window != null) {
126147
alert.initOwner(window);
127148
}
128149
final StringWriter sw = new StringWriter();

0 commit comments

Comments
 (0)