Jump to:

23368 Posts in 18143 Topics by 2863 members

General Questions

SilverStripe Forums » General Questions » Google Translate Code

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1256 Views
  • sebastiankozub
    Avatar
    Community Member
    40 Posts

    Google Translate Code Link to this post

    Hi, I'd like to use Google translate Element -> http://translate.google.com/translate_tools

    I tried to do it 2 ways:

    1) I just copy and paste whole code to Page.ss template

    <div id="google_translate_element"></div><script>
    function googleTranslateElementInit() {
    new google.translate.TranslateElement({
    pageLanguage: 'pl'
    }, 'google_translate_element');
    }
    </script><script src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>

    2) I add the <div id="google_translate_element"></div><script> to the Page.ss and JS to the Page Controller

          Requirements::javascript("http://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit");
          Requirements::customScript(<<<JS
    function googleTranslateElementInit() {
    new google.translate.TranslateElement({pageLanguage: "pl"}, "google_translate_element");
    };
    JS
    );

    It works in IE 8.0 but doesn't works in FF, Chrome, Opera...
    Have you got any ideas... the code works on other not SS sites

    site is here -> http://87.207.57.202/boston/

  • Ryan M.
    Avatar
    Community Member
    309 Posts

    Re: Google Translate Code Link to this post

    I think I see the translate stuff just fine. See attached screenshot:

    Did you flush the template cache and empty your browser cache? If you haven't, empty your browser cache and do this: http://87.207.57.202/boston/?flush=all

    By the way, tested in Mac FF and Mac Chrome.

    Attached Files
  • sebastiankozub
    Avatar
    Community Member
    40 Posts

    Re: Google Translate Code Link to this post

    Yes, it's OK now because I have removed the first ilne from template that generate page in XML. XML was the barrier for javascript modifaction on DOM.

    1256 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.