From 9032715e1036defe982c95e0fcafbaac93f08ba3 Mon Sep 17 00:00:00 2001 From: Samir Date: Mon, 29 May 2023 22:46:47 +0200 Subject: [PATCH] add multi-language support --- src/main/java/dev/samir/vmdconverter/App.java | 11 +++- .../dev/samir/vmdconverter/AppController.java | 21 +++++- .../{vmdconverter.fxml => englisch.fxml} | 4 +- .../dev/samir/vmdconverter/german.fxml | 66 +++++++++++++++++++ 4 files changed, 99 insertions(+), 3 deletions(-) rename src/main/resources/dev/samir/vmdconverter/{vmdconverter.fxml => englisch.fxml} (91%) create mode 100644 src/main/resources/dev/samir/vmdconverter/german.fxml diff --git a/src/main/java/dev/samir/vmdconverter/App.java b/src/main/java/dev/samir/vmdconverter/App.java index 0974843..9f3d826 100644 --- a/src/main/java/dev/samir/vmdconverter/App.java +++ b/src/main/java/dev/samir/vmdconverter/App.java @@ -8,17 +8,26 @@ import javafx.stage.Stage; import java.io.IOException; +import java.util.Locale; /** * JavaFX App */ public class App extends Application { + private final Locale locale = Locale.getDefault(); private static Scene scene; @Override public void start(Stage stage) throws IOException { - scene = new Scene(loadFXML("vmdconverter")); + + + if (locale.getDisplayLanguage().equals("Deutsch")){ + scene = new Scene(loadFXML("german")); + + }else { + scene = new Scene(loadFXML("englisch")); + } stage.setResizable(false); stage.setTitle("VMD Converter"); stage.setScene(scene); diff --git a/src/main/java/dev/samir/vmdconverter/AppController.java b/src/main/java/dev/samir/vmdconverter/AppController.java index 37c0f83..8331350 100644 --- a/src/main/java/dev/samir/vmdconverter/AppController.java +++ b/src/main/java/dev/samir/vmdconverter/AppController.java @@ -1,6 +1,8 @@ package dev.samir.vmdconverter; import dev.samir.vmdconverter.utils.ConsoleOutput; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; import javafx.concurrent.Task; import javafx.event.ActionEvent; import javafx.fxml.FXML; @@ -10,6 +12,7 @@ import dev.samir.vmdconverter.converter.VMDConverter; import java.io.File; +import java.io.IOException; import java.io.PrintStream; @@ -31,6 +34,9 @@ public class AppController { @FXML private TextArea consoleLog; + @FXML + private ComboBox comboBox; + private final ObservableList languagesList = FXCollections.observableArrayList("Deutsch (German)", "Englisch (US)"); @FXML @@ -60,10 +66,23 @@ public void outputFieldBrowseButton(final ActionEvent actionEvent) { } @FXML - public void initialize() { + public void initialize(){ ConsoleOutput consoleOutput = new ConsoleOutput(consoleLog); PrintStream consolePrintStream = new PrintStream(consoleOutput); System.setOut(consolePrintStream); + comboBox.setItems(languagesList); + + } + + + @FXML + public void switchLanguage(final ActionEvent actionEvent) throws IOException { + actionEvent.consume(); + if (comboBox.getValue().equals(languagesList.get(0))) { + App.setRoot("german"); + return; + } + App.setRoot("englisch"); } diff --git a/src/main/resources/dev/samir/vmdconverter/vmdconverter.fxml b/src/main/resources/dev/samir/vmdconverter/englisch.fxml similarity index 91% rename from src/main/resources/dev/samir/vmdconverter/vmdconverter.fxml rename to src/main/resources/dev/samir/vmdconverter/englisch.fxml index 5080935..df213aa 100644 --- a/src/main/resources/dev/samir/vmdconverter/vmdconverter.fxml +++ b/src/main/resources/dev/samir/vmdconverter/englisch.fxml @@ -1,6 +1,7 @@ + @@ -12,8 +13,9 @@ - + +