Reputation: 96
i was trying adding Google translate dropdown to a website.
For the sake of simplicity, i added all the code in the same place of the page.
I have added this code (slightly beautified):
<div id="google_translate_element"></div>
<script type="text/javascript">
function googleTranslateElementInit() {
new google.translate.TranslateElement(
{
pageLanguage: 'it',
includedLanguages: 'de,en,es,fr,it',
gaTrack: true,
gaId: 'UA-XXXXXXXX-X'
},
'google_translate_element'
);
}
</script>
<script type="text/javascript" src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
On the Chrome console i receive this error:
Uncaught TypeError: google.translate.TranslateElement is not a function
This error code doesn't show up with a google search, and i don't know what caused it.
Any help is really appreciated...
Thanks!
Upvotes: 0
Views: 8339
Reputation: 2544
You should add google script before your own.
<script type="text/javascript" src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
<script type="text/javascript">
function googleTranslateElementInit() {
new google.translate.TranslateElement(
{
pageLanguage: 'it',
includedLanguages: 'de,en,es,fr,it',
gaTrack: true,
gaId: 'UA-XXXXXXXX-X'
},
'google_translate_element'
);
}
</script>
Upvotes: 4