на моей веб-странице?
Я прочитал в Интернете, что тег code.setAttribute(attr.name, attr.value));
code.innerHTML = span.innerHTML;
span.parentNode.insertBefore(code, span);
span.parentNode.removeChild(span);
}
});
}
// Use MutationObserver to detect Google Translate completion
const observerCallback = (mutationsList, observer) => {
const htmlEl = document.documentElement;
const isTranslated = htmlEl.classList.contains('translated-ltr') || htmlEl.classList.contains('translated-rtl');
if (isTranslated) {
// Page has been translated
console.log("Google Translate detected. Applying span replacements.");
replaceCodeWithSpan();
// You might want to disconnect the observer once done if you don't need further dynamic updates
// observer.disconnect();
} else {
// Translation was likely reverted to original language
console.log("Google Translate reverted or not active. Reverting code replacements if any.");
revertSpanToCode();
}
};
// Configuration for the observer: watch for attribute changes on the element
const observerConfig = { attributes: true, attributeFilter: ['class'], childList: false, characterData: false };
const observer = new MutationObserver(observerCallback);
// --- Your existing Google Translate Element initialization code should be here ---
// This part should be after the definition of the functions above.
function googleTranslateElementInit() {
new google.translate.TranslateElement({
pageLanguage: 'en', // Set your original page language
layout: google.translate.TranslateElement.InlineLayout.VERTICAL // Change this line
}, 'google_translate_element');
}
// --------------------------------------------------------------------------------
// Start observing the element for class changes (which the translator does)
observer.observe(document.documentElement, observerConfig);
jQuery(function ($) {
var $window = $(window);
var $buttonTop = $('.button-top');
$buttonTop.on('click', function () {
$('html, body').animate({
scrollTop: 0,
}, 400);
});
$window.on('scroll', function () {
if ($window.scrollTop() > 300) { // 300 is our threshold in pixels
$buttonTop.addClass('button-top-visible');
} else {
$buttonTop.removeClass('button-top-visible');
}
});
});
Подробнее здесь: [url]https://stackoverflow.com/questions/79831318/how-to-force-google-translate-to-translate-text-between-code-and-code[/url]
Как заставить Google Translate переводить текст внутри тегов [code] на моей веб-странице? Я прочитал в Интернете, что тег code.setAttribute(attr.name, attr.value)); code.innerHTML = span.innerHTML; span.parentNode.insertBefore(code, span); span.parentNode.removeChild(span); } }); }
// Use MutationObserver to detect Google Translate completion const observerCallback = (mutationsList, observer) => { const htmlEl = document.documentElement; const isTranslated = htmlEl.classList.contains('translated-ltr') || htmlEl.classList.contains('translated-rtl');
if (isTranslated) { // Page has been translated console.log("Google Translate detected. Applying span replacements."); replaceCodeWithSpan(); // You might want to disconnect the observer once done if you don't need further dynamic updates // observer.disconnect(); } else { // Translation was likely reverted to original language console.log("Google Translate reverted or not active. Reverting code replacements if any."); revertSpanToCode(); } };
// Configuration for the observer: watch for attribute changes on the element const observerConfig = { attributes: true, attributeFilter: ['class'], childList: false, characterData: false }; const observer = new MutationObserver(observerCallback);
// --- Your existing Google Translate Element initialization code should be here --- // This part should be after the definition of the functions above. function googleTranslateElementInit() { new google.translate.TranslateElement({ pageLanguage: 'en', // Set your original page language layout: google.translate.TranslateElement.InlineLayout.VERTICAL // Change this line }, 'google_translate_element'); } // --------------------------------------------------------------------------------
// Start observing the element for class changes (which the translator does) observer.observe(document.documentElement, observerConfig);
jQuery(function ($) { var $window = $(window); var $buttonTop = $('.button-top'); $buttonTop.on('click', function () { $('html, body').animate({ scrollTop: 0, }, 400); }); $window.on('scroll', function () { if ($window.scrollTop() > 300) { // 300 is our threshold in pixels $buttonTop.addClass('button-top-visible'); } else { $buttonTop.removeClass('button-top-visible'); } }); });