Help to call function

Asked

Viewed 62 times

-1

Hello, I am in a project of a translation of a system that is actually a directory structure and I decided to use Google translator to do this, using the following block of code

 <script>
var comboGoogleTradutor = null; //Varialvel global

function googleTranslateElementInit() {
    new google.translate.TranslateElement({
        pageLanguage: 'pt',
        includedLanguages: 'en,es,pt',
        layout: google.translate.TranslateElement.InlineLayout.HORIZONTAL
    }, 'google_translate_element');

    comboGoogleTradutor = document.getElementById("google_translate_element").querySelector(".goog-te-combo");
}

function changeEvent(el) {
    if (el.fireEvent) {
        el.fireEvent('onchange');
    } else {
        var evObj = document.createEvent("HTMLEvents");

        evObj.initEvent("change", false, true);
        el.dispatchEvent(evObj);
    }
}

function trocarIdioma(sigla) {
    if (comboGoogleTradutor) {
        comboGoogleTradutor.value = sigla;
        changeEvent(comboGoogleTradutor);//Dispara a troca
    }
}
</script>

But when I authenticate in the system, the dynamic fields (List and derivatives) do not translate automatically, only if I call the translation again on a button

inserir a descrição da imagem aqui

I’ve tried $Document.ready for the code to run again when the screen is loaded and with an if, if the English option was selected on the last page, but I can’t. Someone can give me a light?

1 answer

0

Oops, have you tried calling your function in window.load?

'''

window.onload = function(){
    console.log('Onload disparado');
}

'''

Can you use jquery? In jquery you can use $(Document). ready()

'''

$(document).ready(function(){
  console.log('Ready disparado');
});

'''

In native javascript you can imitate the above event in this way too.

'''

document.addEventListener("DOMContentLoaded", function(event) {
  console.log("DOM completamente carregado e analisado");
});

''' '''

for(var i=0; i< 1000000000; i++)
{}

'''

I hope I’ve helped.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.