I am trying to create a Button to translate my website to Spanish. I am using the already provided code by google, but the issue with the code is that it creates a drop down menu to select Spanish language. I want the website to be translated after clicking down the button without having to use the dropdown menu.
<div id="google_translate_element"></div>
<script type="text/javascript">
function googleTranslateElementInit() {
new google.translate.TranslateElement({pageLanguage: 'en', includedLanguages: 'es', layout: google.translate.TranslateElement.InlineLayout.SIMPLE, autoDisplay: false}, 'google_translate_element');
}
</script>
<script type="text/javascript" src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
The code above creates the dropdown menu in order to select Spanish instead of using the button to automatically translate the page. See below for a screenshot of the button and dropdown selector.
I already tried creating the button using the onclick parameter in order to call the googleTranslateElementInit()
fuction, but is not working
<button type="button" class="button" id="clickMe" onclick="googleTranslateElementInit()">Español</button>