2121import java .io .StringWriter ;
2222import java .time .LocalDate ;
2323import java .util .List ;
24+ import java .util .Locale ;
2425import java .util .Optional ;
2526import 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