Author Topic: Google or Bing Translate website widget  (Read 2282 times)

Offline Nicky

  • Posts: 88
  • Gender: Male
Google or Bing Translate website widget
« on: July 25, 2017, 10:27:58 PM »
Hello Bakers!

Google or Bing Translate website widget ...

If I embed their javascript in my wb template, they load ok ( either of them ).
But I want to add their javascript to specific wb pages but I cannot get those script(s) to load !
Nothing appears, nor any errors.

Here's the Google's javascript ...

<div id="google_translate_el ement"></div><script type="text/javascript">
function googleTranslateElem entInit() {
  new google.translate.Tr anslateElement({pageLanguage: 'en', layout: google.translate.Tr anslateElement.Inli neLayout.SIMPLE, autoDisplay: false, multilanguagePage: true}, 'google_translate_el ement');
}
</script><script type="text/javascript" src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>       

After many days trying different things, what do I need to do to fix this please? 

WB-Version 2.10.0

Regards,
N

ps.  I've got a weather widget javascript on my home page and that works fine in a wb section !?  (Y)

Offline Ruud

  • Posts: 3650
  • Gender: Male
  • Do not use PM for help! Please use the forum!
    • Dev4Me - Professional WebsiteBaker Development
Re: Google or Bing Translate website widget
« Reply #1 on: July 25, 2017, 11:21:48 PM »
Use an extra section of the type "Code". This allows you to use php code.
In that section you can use the "echo" command to output the code like this:
(note the escaped single quotes in the javascript call!)

Code: [Select]
echo '
<div id="google_translate_element"></div>
<script type="text/javascript">
  function googleTranslateElementInit() {
    new google.translate.TranslateElement({pageLanguage: \'en\', layout: google.translate.TranslateElement.InlineLayout.SIMPLE, autoDisplay: false, multilanguagePage: true}, \'google_translate_element\');
  }
</script>
<script type="text/javascript" src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
';

Offline Nicky

  • Posts: 88
  • Gender: Male
Re: Google or Bing Translate website widget
« Reply #2 on: July 26, 2017, 01:50:44 PM »
Many thanks Ruud !

You're a genius  (Y)  :-D