function translatePage(targetLang) { const contentDiv = $('#default'); const originalContent = contentDiv.html(); // Capture full HTML content $('#translateError').html(''); $.ajax({ url: 'translate.php', method: 'POST', data: { content: originalContent, target: targetLang, source: 'en' // Assuming original language is English }, success: function(response) { // Update the page content with the translated HTML contentDiv.html(response.translatedText); }, error: function(xhr, status, error) { // Optionally show an error message $('#translateError').html(error); } }); } function translateSomePageElements(targetLang) { const contentDiv = $('#default'); contentDiv.children().each(function(ix, childElement) { if (childElement.tagName != 'BASE' && childElement.tagName != 'META' && childElement.tagName != 'STYLE' && childElement.tagName != 'SCRIPT' && childElement.tagName != 'IFRAME' && childElement.tagName != 'NOSCRIPT') { //console.log(childElement.tagName); var ele = $(this); $.ajax({ url: 'translate.php', method: 'POST', data: { content: ele.html(), target: targetLang, source: $('#Language').val() }, success: function(response) { // Update the page content with the translated HTML //ele.html(response.translatedText); }, error: function(xhr, status, error) { // Optionally show an error message //console.log(error); //$('#translateError').html(error); } }); } }); } function translatePageElements(div,targetLang) { const contentDiv = $('#'+div); //console.log(contentDiv); contentDiv.children().each(function(ix, childElement) { if (childElement.tagName != 'BASE' && childElement.tagName != 'META' && childElement.tagName != 'STYLE' && childElement.tagName != 'SCRIPT' && childElement.tagName != 'IFRAME' && childElement.tagName != 'NOSCRIPT') { //console.log(childElement.tagName); var ele = $(this); $.ajax({ url: 'translate.php', method: 'POST', data: { content: ele.html(), target: targetLang, source: $('#Language').val() }, success: function(response) { // Update the page content with the translated HTML //console.log(ele. ele.html(response.translatedText); }, error: function(xhr, status, error) { // Optionally show an error message console.log(error); $('#translateError').html(error); } }); } }); }