// Function to set the selected language function setSelectedLanguage(lang) { // Update the selected language display $("#selectedFlag").attr("src", $(".option[data-lang='" + lang + "'] img").attr("src")); $("#selectedText").text(lang);
// Hide all contents $(".En, .عربي").hide(); debugger; if (lang === "En") { $(".En").show(); window.location.reload(); lang = "عربي"; //
} else if (lang === "عربي") { $(".عربي").show(); lang = "En"; // }
localStorage.setItem("selectedLanguage", lang); // window.location.reload();
}
// Check if a language is stored in local storage var storedLang = localStorage.getItem("selectedLanguage"); // window.location.reload(); if (storedLang) { setSelectedLanguage(storedLang); // window.location.reload(); } else { // If no language is stored, default to English ("En") setSelectedLanguage("En"); }
$(".selected-language").click(function () { $(".language-options").toggle();
});
$(".option").click(function () { var selectedLang = $(this).data('lang');
// Store the selected language in local storage localStorage.setItem("selectedLanguage", selectedLang);
setSelectedLanguage(selectedLang); $(".language-options").hide(); // window.location.reload(); });
//Code to hide the flag dropdown when click outside the page $(document).on("click", function(event){ var $trigger = $(".selectedLang"); //debugger; var check = event.target.id; if(check === "selectedText" || check ==="selLang" || check==="seloption" || check==="selectedFlag") {
} else{ $(".language-options").hide(); }
});