Skip to main content

Backup of Code - Google

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Custom Google Translate</title>
    <style>
        /* Style the Google Translate menu container (not inside the iframe) */
        #google-translate-menu {
            border: 2px solid #007bff !important;
            background-color: #f0f8ff !important;
            padding: 6px 12px !important;
            font-size: 14px !important;
            font-family: Arial, sans-serif !important;
            border-radius: 4px !important;
            box-shadow: 0 0 5px rgba(0, 0, 0, 0.1) !important;
            cursor: pointer !important;
        }
.goog-te-gadget-simple .VIpgJd-ZVi9od-xl07Ob-lTBxed {
    color: #fff!important;
}
        /* Optional: Hover effect for the menu container */
        #google-translate-menu:hover {
            background-color: #e6f7ff !important;
        }

        /* Optionally hide Google branding */
        .goog-logo-link, .goog-te-gadget span {
            display: none !important;
        }

        /* Optional: Remove the banner frame (if present) */
        .goog-te-banner-frame.skiptranslate {
            display: none !important;
        }
    </style>
</head>
<body>
    <div id="google-translate-menu" role="menuitem" tabindex="0" aria-label="Translate this site"></div>

    <script>
        function replaceGoogleTranslateMenuItem() {
            const menuItems = document.querySelectorAll('.sl-modern-menu [role="menuitem"]');

            for (const item of menuItems) {
                if (item.textContent.trim() === 'Google Translate') {
                    const parentLi = item.closest('li');
                    if (parentLi) {
                        parentLi.innerHTML = '<div id="google-translate-menu" role="menuitem" tabindex="0" aria-label="Translate this site"></div>';
                        break;
                    }
                }
            }
        }

        function loadGoogleTranslate() {
            const script = document.createElement('script');
            script.type = 'text/javascript';
            script.src = 'https://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit';
            document.head.appendChild(script);
        }

        function googleTranslateElementInit() {
            new google.translate.TranslateElement({
                pageLanguage: 'en',
                layout: google.translate.TranslateElement.InlineLayout.SIMPLE
            }, 'google-translate-menu');
        }

        // Wait for DOM to be ready and then load Google Translate
        window.addEventListener('DOMContentLoaded', () => {
            replaceGoogleTranslateMenuItem();
            loadGoogleTranslate();
        });
    </script>
</body>
</html>