From bcf7a4237d7dcaa76143ca07c0be5dccd7ef1961 Mon Sep 17 00:00:00 2001 From: Harrison Shu Date: Thu, 11 Apr 2024 09:11:53 -0700 Subject: [PATCH 1/2] right to left translation --- public/js/medical/medical.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/public/js/medical/medical.js b/public/js/medical/medical.js index dab47b48c..fcef00a57 100644 --- a/public/js/medical/medical.js +++ b/public/js/medical/medical.js @@ -338,7 +338,7 @@ $(document).ready(function () { // tabs for (let i = 1; i < jsonObj.length; i++) { - textToTranslate = textToTranslate + " $ " + $(jsonObj[i].id).val(); // DELIM = $ + textToTranslate = textToTranslate + " $ " + $(jsonObj[i].id).val(); jsonObj[i].text = $(jsonObj[i].id).val(); } @@ -349,6 +349,7 @@ $(document).ready(function () { data: {text : textToTranslate, patientId: patientId}, success: function(translation){ var listTranslated = translation.split("$"); + var textTranslated = translation; for (let i = 0; i < jsonObj.length; i++) { var textOut = listTranslated[i]; From c6ab0181aa023967e3821e45c3808c7d2fda1ab9 Mon Sep 17 00:00:00 2001 From: Harrison Shu Date: Thu, 11 Apr 2024 10:21:18 -0700 Subject: [PATCH 2/2] implemented show original text directionality --- .../ui/controllers/MedicalController.java | 9 +++- public/css/medical/medical.css | 5 +++ public/js/medical/medical.js | 43 +++++++++++++++++-- 3 files changed, 53 insertions(+), 4 deletions(-) diff --git a/app/femr/ui/controllers/MedicalController.java b/app/femr/ui/controllers/MedicalController.java index ea83d6982..4f569d8b9 100644 --- a/app/femr/ui/controllers/MedicalController.java +++ b/app/femr/ui/controllers/MedicalController.java @@ -274,7 +274,14 @@ public Result translateGet() { PatientEncounterItem patientEncounter = currentEncounterByPatientId.getResponseObject(); String fromLanguage = patientEncounter.getLanguageCode(); - return ok(Json.toJson(translate(text, fromLanguage, toLanguage))); + // add whether the language is rtl to response + List rtlLanguages = Arrays.asList("he", "ar"); + Map responseMap = new HashMap<>(); + responseMap.put("toLanguageIsRtl", rtlLanguages.contains(toLanguage)); + responseMap.put("fromLanguageIsRtl", rtlLanguages.contains(fromLanguage)); + responseMap.put("translation", translate(text, fromLanguage,toLanguage)); + + return ok(Json.toJson(responseMap)); } // Calls Python Script to translate diff --git a/public/css/medical/medical.css b/public/css/medical/medical.css index 97cab86ea..c2e92ac45 100644 --- a/public/css/medical/medical.css +++ b/public/css/medical/medical.css @@ -322,4 +322,9 @@ http://api.thumbr.it/whitenoise-361x370.png?background=#d4d3ccff&noise=626262&de width: auto; margin-right: 5px; +} + +.rtl { + direction: rtl; + text-align: right; } \ No newline at end of file diff --git a/public/js/medical/medical.js b/public/js/medical/medical.js index 41a5f67bc..69d431550 100644 --- a/public/js/medical/medical.js +++ b/public/js/medical/medical.js @@ -347,12 +347,13 @@ $(document).ready(function () { type: 'get', url: '/translate', data: {text : textToTranslate, patientId: patientId}, - success: function(translation){ + success: function(response){ $("#loading").remove(); $("#toggleBtn").text("Show Original"); - var listTranslated = translation.split("$"); - var textTranslated = translation; + var listTranslated = response.translation.split("$"); + var toLanguageIsRtl = response.toLanguageIsRtl; + var fromLanguageIsRtl = response.fromLanguageIsRtl; for (let i = 0; i < jsonObj.length; i++) { var textOut = listTranslated[i]; @@ -360,11 +361,23 @@ $(document).ready(function () { if (jsonObj[i].id === "#complaintInfo"){ var oldText = $(jsonObj[i].id + " span").text(); $(jsonObj[i].id + "Store").text(oldText) + $(jsonObj[i].id + "Store").data('isRtl', fromLanguageIsRtl); // store whether langauge is rtl $(jsonObj[i].id).text(textOut) + $(jsonObj[i].id).data('isRtl', toLanguageIsRtl); + } else { var oldText = $(jsonObj[i].id).val(); $(jsonObj[i].id + "Store").text(oldText) + $(jsonObj[i].id + "Store").data('isRtl', fromLanguageIsRtl); $(jsonObj[i].id).val(textOut); + $(jsonObj[i].id).data('isRtl', toLanguageIsRtl); + } + + // make the text right to left if it is a rtl language + if ($(jsonObj[i].id).data('isRtl')) { + $(jsonObj[i].id).addClass('rtl'); + } else { + $(jsonObj[i].id).removeClass('rtl'); } } }, @@ -400,12 +413,36 @@ $(document).ready(function () { $(jsonObj[0].id + "Store").text(oldText); $(jsonObj[0].id).text(newText); + // switch and set the rtl values + var storeRtl = $(jsonObj[0].id + "Store").data("isRtl"); + var currentRtl = $(jsonObj[0].id).data("isRtl"); + $(jsonObj[0].id + "Store").data("isRtl",currentRtl); + $(jsonObj[0].id).data("isRtl",storeRtl); + + if($(jsonObj[0].id).data("isRtl")) { + $(jsonObj[0].id).addClass('rtl'); + } else { + $(jsonObj[0].id).removeClass('rtl'); + } + // toggle tabs for (let i = 1; i < jsonObj.length; i++) { var oldText = $(jsonObj[i].id).val(); var newText = $(jsonObj[i].id + "Store").text(); $(jsonObj[i].id + "Store").text(oldText); $(jsonObj[i].id).val(newText); + + // switch and set the rtl values + var storeRtl = $(jsonObj[i].id + "Store").data("isRtl"); + var currentRtl = $(jsonObj[i].id).data("isRtl"); + $(jsonObj[i].id + "Store").data("isRtl",currentRtl); + $(jsonObj[i].id).data("isRtl",storeRtl); + + if($(jsonObj[i].id).data("isRtl")) { + $(jsonObj[i].id).addClass('rtl'); + } else { + $(jsonObj[i].id).removeClass('rtl'); + } } });