diff --git a/authentication-demo-ui/src/main/java/io/mosip/authentication/demo/service/IdaController.java b/authentication-demo-ui/src/main/java/io/mosip/authentication/demo/service/IdaController.java index 7a33e67c2bb..65d2e1ad221 100644 --- a/authentication-demo-ui/src/main/java/io/mosip/authentication/demo/service/IdaController.java +++ b/authentication-demo-ui/src/main/java/io/mosip/authentication/demo/service/IdaController.java @@ -30,6 +30,7 @@ import javax.net.ssl.TrustManager; import javax.net.ssl.X509TrustManager; +import io.mosip.authentication.demo.util.ApplicationResourceContext; import io.mosip.biometrics.util.ConvertRequestDto; import io.mosip.biometrics.util.face.FaceDecoder; import javafx.fxml.FXMLLoader; @@ -180,6 +181,8 @@ public class IdaController { @FXML private GridPane previewGrid; + private ResourceBundle labelBundle; + @FXML private void initialize() { responsetextField.setText(null); @@ -209,6 +212,7 @@ private void initialize() { otpValue.textProperty().addListener((observable, oldValue, newValue) -> { updateSendButton(); }); + labelBundle = ApplicationResourceContext.getInstance().getLabelBundle(); } @FXML @@ -406,7 +410,7 @@ private String getCaptureRequestTemplate() { } private String captureFingerprint() throws Exception { - responsetextField.setText("Capturing Fingerprint..."); + responsetextField.setText(labelBundle.getString("capturingBiometric")); responsetextField.setStyle("-fx-text-fill: black; -fx-font-size: 20px; -fx-font-weight: bold"); String requestBody = getCaptureRequestTemplate(); @@ -452,7 +456,7 @@ private String getFaceDeviceSubId() { } private String captureIris() throws Exception { - responsetextField.setText("Capturing Iris..."); + responsetextField.setText(labelBundle.getString("capturingIris")); responsetextField.setStyle("-fx-text-fill: black; -fx-font-size: 20px; -fx-font-weight: bold"); String requestBody = getCaptureRequestTemplate(); @@ -475,7 +479,7 @@ private String captureIris() throws Exception { } private String captureFace() throws Exception { - responsetextField.setText("Capturing Face..."); + responsetextField.setText(labelBundle.getString("capturingFace")); responsetextField.setStyle("-fx-text-fill: black; -fx-font-size: 20px; -fx-font-weight: bold"); String requestBody = getCaptureRequestTemplate(); @@ -553,7 +557,7 @@ private String capturebiometrics(String requestBody) throws Exception { } bR.close(); } catch (IOException e) { - responsetextField.setText("Device connectivity failed...."); + responsetextField.setText(labelBundle.getString("deviceConnectivityFailed")); responsetextField.setStyle("-fx-text-fill: red; -fx-font-size: 20px; -fx-font-weight: bold"); e.printStackTrace(); } @@ -571,7 +575,7 @@ private String capturebiometrics(String requestBody) throws Exception { Map errorMap = (Map) e.get("error"); error = errorMap.get("errorCode").toString(); if (error.equals(DEFAULT_SUBID) || error.equals("100")) { - responsetextField.setText("Capture Success"); + responsetextField.setText(labelBundle.getString("captureSuccess")); responsetextField.setStyle("-fx-text-fill: green; -fx-font-size: 20px; -fx-font-weight: bold"); ObjectMapper objectMapper = new ObjectMapper(); List dataList = (List) objectMapper.readValue(result.getBytes(), Map.class).get("biometrics"); @@ -583,7 +587,7 @@ private String capturebiometrics(String requestBody) throws Exception { previousHash = (String) b.get("hash"); } } else { - responsetextField.setText("Capture Failed"); + responsetextField.setText(labelBundle.getString("captureFailed")); responsetextField.setStyle("-fx-text-fill: red; -fx-font-size: 20px; -fx-font-weight: bold"); break; } @@ -621,7 +625,7 @@ private void onRequestOtp() { if (response.getStatusCode().is2xxSuccessful()) { List errors = ((List) response.getBody().get("errors")); boolean status = errors == null || errors.isEmpty(); - String responseText = status ? "OTP Request Success" : "OTP Request Failed"; + String responseText = status ? labelBundle.getString("otpRequestSuccess") : labelBundle.getString("otpRequestFail"); if (status) { responsetextField.setStyle("-fx-text-fill: green; -fx-font-size: 20px; -fx-font-weight: bold"); } else { @@ -629,7 +633,7 @@ private void onRequestOtp() { } responsetextField.setText(responseText); } else { - responsetextField.setText("OTP Request Failed with Error"); + responsetextField.setText(labelBundle.getString("otpRequestFailedwithError")); responsetextField.setStyle("-fx-text-fill: red; -fx-font-size: 20px; -fx-font-weight: bold"); } @@ -684,7 +688,7 @@ public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttp private void onSendAuthRequest() throws Exception { responsetextField.setText(null); responsetextField.setStyle("-fx-text-fill: black; -fx-font-size: 20px; -fx-font-weight: bold"); - responsetextField.setText("Preparing Auth Request..."); + responsetextField.setText(labelBundle.getString("prepareAuthRequest")); AuthRequestDTO authRequestDTO = new AuthRequestDTO(); // Set Auth Type AuthTypeDTO authTypeDTO = new AuthTypeDTO(); @@ -709,7 +713,7 @@ private void onSendAuthRequest() throws Exception { if (isBioAuthType()) { identityBlock.put("biometrics", mapper.readValue(capture, Map.class).get("biometrics")); } - responsetextField.setText("Encrypting Auth Request..."); + responsetextField.setText(labelBundle.getString("encryptAuthRequest")); System.out.println("******* Request before encryption ************ \n\n"); System.out.println(mapper.writeValueAsString(identityBlock)); EncryptionRequestDto encryptionRequestDto = new EncryptionRequestDto(); @@ -719,11 +723,11 @@ private void onSendAuthRequest() throws Exception { kernelEncrypt = kernelEncrypt(encryptionRequestDto, false); } catch (Exception e) { e.printStackTrace(); - responsetextField.setText("Encryption of Auth Request Failed"); + responsetextField.setText(labelBundle.getString("encryptAuthRequestFailed")); return; } - responsetextField.setText("Authenticating..."); + responsetextField.setText(labelBundle.getString("authenticate")); // Set request block authRequestDTO.setRequest(requestDTO); @@ -757,17 +761,17 @@ private void onSendAuthRequest() throws Exception { String response; if(isKycRequired.isSelected()) { - status = (boolean) ((Map) authResponse.getBody().get("response")).get("kycStatus"); - response = status ? objectMapper.writeValueAsString(authResponse.getBody().get("response")) : "KYC Request Failed"; + status = authResponse.getBody().get("response") != null ? (boolean) ((Map) authResponse.getBody().get("response")).get("kycStatus") : false; + response = status ? objectMapper.writeValueAsString(authResponse.getBody().get("response")) : labelBundle.getString("kycRequestFailed"); if(status) { loadKYCPreviewPage(response, status); - response = status ? "Authentication Success" : "Authentication Failed"; + response = status ? labelBundle.getString("authenticationSuccess") : labelBundle.getString("authenticationFail"); } else { - response = status ? "Authentication Success" : "Authentication Failed"; + response = status ? labelBundle.getString("authenticationSuccess") : labelBundle.getString("authenticationFail"); } } else { status = (boolean) ((Map) authResponse.getBody().get("response")).get("authStatus"); - response = status ? "Authentication Success" : "Authentication Failed"; + response = status ? labelBundle.getString("authenticationSuccess") : labelBundle.getString("authenticationFail"); } if (status) { responsetextField.setStyle("-fx-text-fill: green; -fx-font-size: 20px; -fx-font-weight: bold; scroll-bar:horizontal:enabled"); @@ -776,7 +780,7 @@ private void onSendAuthRequest() throws Exception { } responsetextField.setText(response); } else { - responsetextField.setText("Authentication Failed with Error"); + responsetextField.setText(labelBundle.getString("authenticationFailWithError")); responsetextField.setStyle("-fx-text-fill: red; -fx-font-size: 20px; -fx-font-weight: bold"); } @@ -784,7 +788,7 @@ private void onSendAuthRequest() throws Exception { System.out.println(authResponse.getBody()); } catch (Exception e) { e.printStackTrace(); - responsetextField.setText("Authentication Failed with Error"); + responsetextField.setText(labelBundle.getString("authenticationFailWithError")); responsetextField.setStyle("-fx-text-fill: red; -fx-font-size: 20px; -fx-font-weight: bold"); } } @@ -960,10 +964,10 @@ public static String getTransactionID() { @FXML private void onReset() { Alert alert = new Alert(Alert.AlertType.CONFIRMATION); - alert.setTitle("Confirm Reset"); - alert.setContentText("Are you sure to reset?"); - ButtonType okButton = new ButtonType("Yes", ButtonBar.ButtonData.YES); - ButtonType noButton = new ButtonType("No", ButtonBar.ButtonData.NO); + alert.setTitle(labelBundle.getString("confirmreset")); + alert.setContentText(labelBundle.getString("resetComfirmMessage")); + ButtonType okButton = new ButtonType(labelBundle.getString("yes"), ButtonBar.ButtonData.YES); + ButtonType noButton = new ButtonType(labelBundle.getString("no"), ButtonBar.ButtonData.NO); alert.getButtonTypes().setAll(okButton, noButton); alert.showAndWait().ifPresent(type -> { if (type.getButtonData().equals(ButtonType.YES.getButtonData())) { @@ -1293,7 +1297,7 @@ private void renderView(JSONObject jsonObject, boolean status) throws Exception statusLabel.setMaxHeight(100); statusLabel.setPrefWidth(400); statusLabel.setAlignment(Pos.CENTER); - statusLabel.setText("EKYC Preview"); + statusLabel.setText(labelBundle.getString("ekycPreviewLabel")); statusLabel.setStyle("-fx-text-fill: green; -fx-font-size: 20px; -fx-font-weight: bold; scroll-bar:horizontal:enabled"); HBox statusHBox1 = new HBox(); diff --git a/authentication-demo-ui/src/main/java/io/mosip/authentication/demo/service/IdaStarter.java b/authentication-demo-ui/src/main/java/io/mosip/authentication/demo/service/IdaStarter.java index 2382c6eb3c2..10733053bae 100644 --- a/authentication-demo-ui/src/main/java/io/mosip/authentication/demo/service/IdaStarter.java +++ b/authentication-demo-ui/src/main/java/io/mosip/authentication/demo/service/IdaStarter.java @@ -2,6 +2,8 @@ import java.io.IOException; +import io.mosip.authentication.demo.util.ApplicationResourceContext; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.context.ConfigurableApplicationContext; @@ -14,6 +16,7 @@ import javafx.scene.Scene; import javafx.scene.layout.GridPane; import javafx.stage.Stage; +import org.springframework.core.env.Environment; /** * The Class IdaStarter. @@ -38,7 +41,10 @@ public void init() throws Exception { context = builder.run(getParameters().getRaw().toArray(new String[0])); loader.setControllerFactory(context::getBean); + ApplicationResourceContext.getInstance().setApplicatioLanguage(context.getEnvironment().getProperty("mosip.primary-language")); + loader.setResources(ApplicationResourceContext.getInstance().getLabelBundle()); root = loader.load(this.getClass().getClassLoader().getResourceAsStream("fxml/idaFXML.fxml")); + context.close(); } diff --git a/authentication-demo-ui/src/main/java/io/mosip/authentication/demo/util/ApplicationResourceContext.java b/authentication-demo-ui/src/main/java/io/mosip/authentication/demo/util/ApplicationResourceContext.java new file mode 100644 index 00000000000..73c240b92c9 --- /dev/null +++ b/authentication-demo-ui/src/main/java/io/mosip/authentication/demo/util/ApplicationResourceContext.java @@ -0,0 +1,41 @@ +package io.mosip.authentication.demo.util; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.env.Environment; +import org.springframework.stereotype.Component; + +import java.util.Locale; +import java.util.ResourceBundle; + +public class ApplicationResourceContext { + + String applicatioLanguage; + ResourceBundle labelBundle; + + private static ApplicationResourceContext context; + private ApplicationResourceContext() { + + } + + private void loadResource(){ + Locale applicationPrimaryLanguageLocale = new Locale(applicatioLanguage != null ? applicatioLanguage.substring(0, 2) : "en"); + labelBundle = ResourceBundle.getBundle("labels", applicationPrimaryLanguageLocale); + } + public static ApplicationResourceContext getInstance() { + if(context == null) { + context = new ApplicationResourceContext(); + return context; + } else { + return context; + } + } + + public ResourceBundle getLabelBundle() { + return labelBundle; + } + + public void setApplicatioLanguage(String applicatioLanguage) { + this.applicatioLanguage = applicatioLanguage; + loadResource(); + } +} diff --git a/authentication-demo-ui/src/main/resources/application.properties b/authentication-demo-ui/src/main/resources/application.properties index 78a51de55c1..fde6d722c34 100644 --- a/authentication-demo-ui/src/main/resources/application.properties +++ b/authentication-demo-ui/src/main/resources/application.properties @@ -29,7 +29,7 @@ mosip.kernel.crypto.sign-algorithm-name=SHA512withRSA logging.level.org.springframework=OFF logging.level.root=OFF spring.main.banner-mode=off - +mosip.primary-language=eng clientId=mosip-regproc-client secretKey=abc123 diff --git a/authentication-demo-ui/src/main/resources/fxml/idaFXML.fxml b/authentication-demo-ui/src/main/resources/fxml/idaFXML.fxml index 948c12b4edc..ebb2f2d3022 100644 --- a/authentication-demo-ui/src/main/resources/fxml/idaFXML.fxml +++ b/authentication-demo-ui/src/main/resources/fxml/idaFXML.fxml @@ -27,7 +27,7 @@ - @@ -55,11 +55,11 @@ - @@ -93,19 +93,19 @@ - - - @@ -122,12 +122,12 @@ -