WebsiteBaker Community Forum

WebsiteBaker Support (2.10.x) => General Help & Support => Topic started by: Nicky on July 25, 2017, 10:27:58 PM

Title: Google or Bing Translate website widget
Post by: Nicky 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)
Title: Re: Google or Bing Translate website widget
Post by: Ruud 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>
';
Title: Re: Google or Bing Translate website widget
Post by: Nicky on July 26, 2017, 01:50:44 PM
Many thanks Ruud !

You're a genius  (Y)  :-D