Skip to content

Commit

Permalink
Updated Language Translation
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBear1616 committed Feb 28, 2024
1 parent 0c0ae70 commit b1f8ace
Show file tree
Hide file tree
Showing 7 changed files with 218 additions and 49 deletions.
4 changes: 4 additions & 0 deletions app/femr/common/dtos/CurrentUser.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public class CurrentUser {
private Integer tripId;
long SessionTimeOut;

private String languageCode = "ka";

public CurrentUser(int id, String firstName, String lastName, String email, List<IRole> roles, Integer tripId, long time) {
this.id = id;
this.firstName = firstName;
Expand Down Expand Up @@ -73,4 +75,6 @@ public Integer getTripId() {
public long getTimeout2() {
return SessionTimeOut;
}

public String getLanguageCode() { return languageCode; }
}
66 changes: 29 additions & 37 deletions app/femr/ui/views/home/index.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,49 +15,41 @@

</script>
<script>
let languageData;
fetch('@routes.Assets.versioned("json/languages.json")')
.then(response => response.json())
.then(data => {
languageData = data;
updateLanguage('en');
});
document.addEventListener('DOMContentLoaded', function(event) {
let languageData;
fetch('@routes.Assets.versioned("json/languages.json")')
.then(response => response.json())
.then(data => {
languageData = data;
updateLanguage();
});

document.getElementById('languageSelect').addEventListener('change', function() {
updateLanguage(this.value);
});
// document.getElementById('languageSelect').addEventListener('change', function() {
// updateLanguage(this.value);
// });

function updateTextContent(elementId, value) {
const element = document.getElementById(elementId);
if (element) {
element.textContent = value;
function updateTextContent(elementId, value) {
const element = document.getElementById(elementId);
if (element) {
element.textContent = value;
}
}
}

function updateLanguage(language) {
const currentUser = " @currentUser.getFirstName()";
updateTextContent("home_index_h2_Welcome", languageData[language].home_index_h2_Welcome + currentUser);
updateTextContent("home_index_div_Your", languageData[language].home_index_div_Your);
updateTextContent("home_index_p_Please", languageData[language].home_index_p_Please);
updateTextContent("home_index_p_Or", languageData[language].home_index_p_Or);
updateTextContent("home_index_p_Search", languageData[language].home_index_p_Search);
const patientSearch = document.getElementById("patientSearch");
if (patientSearch) {
patientSearch.placeholder = languageData[language].home_index_div_ID;
function updateLanguage() {
const language = "@currentUser.getLanguageCode";
const currentUser = " @currentUser.getFirstName()";
updateTextContent("home_index_h2_Welcome", languageData[language].home_index_h2_Welcome + currentUser);
updateTextContent("home_index_div_Your", languageData[language].home_index_div_Your);
updateTextContent("home_index_p_Please", languageData[language].home_index_p_Please);
updateTextContent("home_index_p_Or", languageData[language].home_index_p_Or);
updateTextContent("home_index_p_Search", languageData[language].home_index_p_Search);
const patientSearch = document.getElementById("patientSearch");
if (patientSearch) {
patientSearch.placeholder = languageData[language].home_index_div_ID;
}
}
updateTextContent("langCode_triage", languageData[language].langCode_triage);
updateTextContent("langCode_medical", languageData[language].langCode_medical);
updateTextContent("langCode_pharmacy", languageData[language].langCode_pharmacy);
updateTextContent("langCode_research", languageData[language].langCode_research);
updateTextContent("langCode_manager", languageData[language].langCode_manager);
updateTextContent("langCode_admin", languageData[language].langCode_admin);
updateTextContent("langCode_superUser", languageData[language].langCode_superUser);
updateTextContent("langCode_reference", languageData[language].langCode_reference);
updateTextContent("langCode_feedbackBtn", languageData[language].langCode_feedbackBtn);
updateTextContent("langCode_googleChrome", languageData[language].langCode_googleChrome);
}
});
</script>

}


Expand Down
2 changes: 1 addition & 1 deletion app/femr/ui/views/layouts/main.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

@content

@footer()
@footer(currentUser, assets)
</div>

@outsideContainerBottom
Expand Down
32 changes: 32 additions & 0 deletions app/femr/ui/views/partials/authenticated.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,38 @@
@import femr.ui.controllers.admin.routes.AdminController
@import femr.ui.controllers.routes.ResearchController
@import femr.ui.controllers.routes.ReferenceController

<script>
document.addEventListener('DOMContentLoaded', function(event) {
let languageData;
fetch('@routes.Assets.versioned("json/languages.json")')
.then(response => response.json())
.then(data => {
languageData = data;
updateLanguage();
});

function updateTextContent(elementId, value) {
const element = document.getElementById(elementId);
if (element) {
element.textContent = value;
}
}

function updateLanguage() {
const language = "@currentUser.getLanguageCode";
updateTextContent("langCode_triage", languageData[language].langCode_triage);
updateTextContent("langCode_medical", languageData[language].langCode_medical);
updateTextContent("langCode_pharmacy", languageData[language].langCode_pharmacy);
updateTextContent("langCode_research", languageData[language].langCode_research);
updateTextContent("langCode_manager", languageData[language].langCode_manager);
updateTextContent("langCode_admin", languageData[language].langCode_admin);
updateTextContent("langCode_superUser", languageData[language].langCode_superUser);
updateTextContent("langCode_reference", languageData[language].langCode_reference);
}
});
</script>

<div class="navigationLogo">
<a href="@HomeController.index()">
<img src="@assets.path("img/logo_color_wordless_sm.png")" />
Expand Down
48 changes: 48 additions & 0 deletions app/femr/ui/views/partials/footer.scala.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
@(currentUser: femr.common.dtos.CurrentUser, assets: AssetsFinder)
<script>
document.addEventListener('DOMContentLoaded', function(event) {
let languageData;
fetch('@routes.Assets.versioned("json/languages.json")')
.then(response => response.json())
.then(data => {
languageData = data;
updateLanguage();
});

function updateTextContent(elementId, value) {
const element = document.getElementById(elementId);
if (element) {
element.textContent = value;
}
}

function updateLanguage() {
const language = "@currentUser.getLanguageCode";
updateTextContent("langCode_feedbackBtn", languageData[language].langCode_feedbackBtn);
updateTextContent("langCode_googleChrome", languageData[language].langCode_googleChrome);
}
});
</script>
<footer>
<hr />
<div class="row">
Expand All @@ -14,3 +39,26 @@
</div>
</div>
</footer>
@*<script>*@
@* document.addEventListener('DOMContentLoaded', function(event) {*@
@* let languageData;*@
@* function translateTextNodes(node) {*@
@* const targetLang = "es";*@
@* if (node.nodeType === Node.TEXT_NODE) {*@
@* const trimmedText = node.nodeValue.trim();*@
@* if (trimmedText !== '' && languageData[targetLang][trimmedText]) {*@
@* node.nodeValue = languageData[targetLang][trimmedText];*@
@* }*@
@* } else {*@
@* node.childNodes.forEach(child => translateTextNodes(child, targetLang));*@
@* }*@
@* }*@

@* fetch('@routes.Assets.versioned("json/languages.json")')*@
@* .then(response => response.json())*@
@* .then(data => {*@
@* languageData = data;*@
@* translateTextNodes(document.body);*@
@* });*@
@* });*@
@*</script>*@
63 changes: 54 additions & 9 deletions app/femr/ui/views/triage/index.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,51 @@
<script type="text/javascript" src="@assets.path("js/shared/vitalClientValidation.js")"></script>
<script type="text/javascript" src="@assets.path("js/libraries/handlebars.min.js")"></script>
<script type="text/javascript" src="@assets.path("js/libraries/typeahead.bundle.min.js")"></script>
<script>
document.addEventListener('DOMContentLoaded', function(event) {
let languageData;
fetch('@routes.Assets.versioned("json/languages.json")')
.then(response => response.json())
.then(data => {
languageData = data;
updateLanguage();
});

function updateTextContent(elementId, value) {
const element = document.getElementById(elementId);
if (element) {
element.textContent = value;
}
}

function updateInputField(identifier, value) {
const inputElement = document.getElementById(identifier);
const labelElement = document.querySelector(`label[for='${identifier}']`);
if (inputElement && labelElement) {
labelElement.textContent = value;
inputElement.placeholder = value;
}

}

function updateLanguage() {
const language = "@currentUser.getLanguageCode";
updateTextContent("triage_index_p_That", languageData[language].triage_index_p_That);
updateTextContent("triage_index_p_Patient", languageData[language].triage_index_p_Patient);
updateTextContent("triage_index_a_Go", languageData[language].triage_index_a_Go);
updateTextContent("triage_index_h2_Check", languageData[language].triage_index_h2_Check);
updateTextContent("triage_index_h2_General", languageData[language].triage_index_h2_General);
const patientDemographics = document.getElementById("triage_index_b_patientDemographics");
if (patientDemographics) {
patientDemographics.title = languageData[language].triage_index_b_patientDemographics;
}
updateInputField("triage_index_firstName", languageData[language].triage_index_firstName);
updateInputField("triage_index_lastName", languageData[language].triage_index_lastName);
updateInputField("triage_index_phoneNumber", languageData[language].triage_index_phoneNumber);
updateInputField("triage_index_address", languageData[language].triage_index_address);
}
});
</script>
}
@additionalStyles = {
<link rel="stylesheet" href="@assets.path("css/triage.css")">
Expand All @@ -33,27 +78,27 @@

<div id="triageContentWrap">
@if(viewModel.isSearchError) {
<p>That patient could not be found.</p>
<p id="triage_index_p_That">That patient could not be found.</p>
}
@if(viewModel.isLinkToMedical()){
<p class="newEncounterWrap"> Patient has an open encounter <a class="btn btn-danger" href="/medical/edit/@viewModel.getPatient().getId()" target="blank">Go To Medical</a></p>
<p class="newEncounterWrap" id="triage_index_p_Patient"> Patient has an open encounter <a class="btn btn-danger" href="/medical/edit/@viewModel.getPatient().getId()" target="blank" id="triage_index_a_Go">Go To Medical</a></p>
}
<h2 class="text-center">Check In - Triage</h2>
<h2 class="text-center" id="triage_index_h2_Check">Check In - Triage</h2>

@helper.form(action = TriageController.indexPost(viewModel.getPatient.getId), 'class -> "form-horizontal triage-form", 'enctype -> "multipart/form-data") {
<div id="genInfoWrap" class="sectionBackground backgroundForWrap">
<h2>General Info
<b title="Complete form with patient demographics as instructed. Any box with an asterix (*) is required. Shared contact information would be if two patients have a household phone or email that they share, for example.">
<h2 id="triage_index_h2_General">General Info
<b id="triage_index_b_patientDemographics" title="Complete form with patient demographics as instructed. Any box with an asterix (*) is required. Shared contact information would be if two patients have a household phone or email that they share, for example.">
<i class="fa fa-question-circle " style="font-size: 0.5em;"></i>
</b>
</h2>
@inputText("First Name", "firstName", true, if(viewModel != null) viewModel.getPatient.getFirstName else null, "text")
@inputText("First Name", "triage_index_firstName", true, if(viewModel != null) viewModel.getPatient.getFirstName else null, "text")
<br>
@inputText("Last Name", "lastName", true, if(viewModel != null) viewModel.getPatient.getLastName else null, "text")
@inputText("Last Name", "triage_index_lastName", true, if(viewModel != null) viewModel.getPatient.getLastName else null, "text")
<br>
@inputText("Phone Number", "phoneNumber", false, if(viewModel != null) viewModel.getPatient.getPhoneNumber else null, "tel")
@inputText("Phone Number", "triage_index_phoneNumber", false, if(viewModel != null) viewModel.getPatient.getPhoneNumber else null, "tel")
<br>
@inputText("Address", "address", false, if(viewModel != null) viewModel.getPatient.getAddress else null, "text")
@inputText("Address", "triage_index_address", false, if(viewModel != null) viewModel.getPatient.getAddress else null, "text")
<br>
<div class="generalInfoInput" id="citySearchContainer">
<label for="city">City<span class="red bold">*</span></label>
Expand Down
Loading

1 comment on commit b1f8ace

@hmaziz
Copy link
Contributor

@hmaziz hmaziz commented on b1f8ace Mar 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved: The team conducted an offline meeting on February 28th, during which they reviewed and approved the commit. In this update, Mayur integrated a new feature that fetches the language_code from the database and applies it to translate the fEMR software's user interface. Initially, the entire logic was encapsulated within a single file. The team suggested modularizing the code by distributing the logic across the relevant pages. Mayur implemented these improvements, ensuring the code was well-organized and maintainable before finalizing the commit/push.

Please sign in to comment.