Google Translate Mod.

Started by wakewatcher, August 18, 2021, 02:10:14 PM

Previous topic - Next topic

wakewatcher

There are a couple of Google Translate Mods here but I didn't have much (any) luck with either of them so I thought I'd hack around and try my hand at my own mod by cobbling together something (which means stealing from others like this time from w3schools.) What I've done is an adaptation of this. I only need, for now, English, Spanish and French. (damn Canadians! :-) I've got a couple of issues with it I'll work on them one at a time.  This first one isn't the end of the world but I'd like to 'fix' it somehow.  First the code.
file ./Themes/default/index.template.php
after:
// Custom banners and shoutboxes should be placed here, before the linktree.

echo '
<div id="google_translate_element"></div>
<script type="text/javascript">
function googleTranslateElementInit() {
 new google.translate.TranslateElement({pageLanguage: \'fr,es,en\', includedLanguages: \'fr,es,en\', layout: google.translate.TranslateElement.InlineLayout.SIMPLE}, \'google_translate_element\');
layout: google.translate.TranslateElement.InlineLayout.SIMPLE}, \'google_translate_element\');
}
</script>

<script type="text/javascript" src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
';

What happens here (and indeed in the w3schools example) is that once you pick a language and then when the translation appears the page is repainted and translated Google adds a Google Translate bar at the top of the page.  I don't need/want it as the new page still has my translate drop down. I thought there might be an option for the google.translate.TranslateElement object but I couldn't find the reference. (I'm google search term impaired apparently.)  I know that the SMF team has done something similar because they have language dropdown on every page but it doesn't show up at the top as well.  I'd be able to use what they/you have done for this site if I knew where to look.
smf 2.0.18

Advertisement: