¡Hola Mundo! ¿Cómo estás?

Soy Marcos Fernández, hago esto por aburrimiento (Es solo texto de prueba).

Esto es lo que debes hacer para agregar la traducción automática con el motor de Google Translate según el idioma del navegador.

Primero agrega esto a tu CSS:


            /* Google translate fix */
                iframe,
                .skiptranslate.goog-te-gadget {
                    display: none;
                }

                #goog-gt-tt {
                    display: none !important;            
                }

                font {
                    background-color: transparent !important;
                    box-shadow: 0 0 !important;
                }

                body {
                    top: 0 !important;
                }
            /* Google translate fix */
        

Finalmente agrega esto en tu JS


            function googleTranslateElementInit() {
                new google.translate.TranslateElement({
                    pageLanguage: 'es',
                    autoDisplay: false
                }, 'google_translate_element');
                let isIframe = false;
                let checkElement = setInterval(() => {
                    var a = document.getElementById(":0.targetLanguage").children[0];
                    var iframe = document.querySelector('[id=":1.container"]')
                    if (a && a.length > 0) {
                        a.dispatchEvent(new Event('change')); 
                        isIframe = true;
                        if(iframe && isIframe) {
                            a.value = 'en';
                            a.dispatchEvent(new Event('change'));
                            clearInterval(checkElement);
                        }
                    }
                }, 500);
            }
        
Ir al CV