var langJSON = { en: {}, mr: {} }; //var appLang = localStorage.getItem("lang"); //if (appLang === null) { // localStorage.setItem("lang", "en"); // Set 'en' as default // appLang = "en"; // Update appLang to 'en' // contentUpdate("en"); // Update content for English //} else { // contentUpdate(appLang); // Update content based on the stored language preference //} var appLang = localStorage.getItem("lang"); if (appLang === null) { localStorage.setItem("lang", "mr"); appLang = "mr"; contentUpdate("mr"); } else { contentUpdate(appLang); } updateButton(); // <-- Move this here, after appLang is set document.documentElement.lang = appLang; // Set // Function to toggle between English and Marathi //function toggleLanguage() { // var newLang = (appLang === 'en') ? 'mr' : 'en'; // localStorage.setItem("lang", newLang); // contentUpdate(newLang); // appLang = newLang; // Update appLang after toggling // updateButton(); // Update button text after toggling // // alert(appLang); // // document.getElementById("appLangDisplay").innerText = appLang; //} function toggleLanguage() { var newLang = (appLang === 'en') ? 'mr' : 'en'; localStorage.setItem("lang", newLang); appLang = newLang; contentUpdate(newLang); // This updates the whole website updateButton(); } // Content/inner HTML update/assign function contentUpdate(langKey) { // Fetch JSON file dynamically based on the selected language fetch('../Content/' + langKey + '.json') .then(response => response.json()) .then(data => { langJSON[langKey] = data; updateContent(langKey); changeDiv(langKey); // Call the function to change the div based on language changeDivdynamic_lag(langKey); // careerDiv(langKey); // for dynamic lang changes }) .catch(error => console.error('Error fetching JSON:', error)); } function updateContent(langKey) { var currLang = langJSON[langKey]; var elements = document.querySelectorAll('[data-key]'); elements.forEach(element => { var dataKey = element.getAttribute('data-key'); if (dataKey in currLang) { element.innerText = currLang[dataKey]; } }); } // Function to update button text based on appLang function updateButton() { var button = document.getElementById('language-toggle'); button.innerText = (appLang === 'en') ? 'मराठी' : 'English'; } // Initial call to update button text updateButton(); //