Jump to:

23486 Posts in 18995 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Google translate

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: 8396 Views
  • frabraha
    Avatar
    Community Member
    49 Posts

    Google translate Link to this post

    I have tried to get the google translate to work with SS, but something strange happens.

    In IE the google translate is showing, but when you choose a language all the font styles change to the browsers default style.
    And in FireFox, I only get a javascript error in firebug that says: "An invalid or illegal string was specified" code: "12
    (function(){function g(a){throw a;}var...ion qa(a,b){return a.currentTarget=b} "

    Have no clue how to fix this, and can't find any help anywhere about this problem.
    I have tried adding the google translate into a html page without SS and it works just fine there, but not in SS.

    Anyone have a clue as to why its not working in Silverstripe?

  • sebastiankozub
    Avatar
    Community Member
    40 Posts

    Re: Google translate Link to this post

    Hi, I have the same problem... any clues?

          Requirements::customScript(<<<JS
    alert("hi there");
    JS
    );

          Requirements::customScript(<<<JS
             function googleTranslateElementInit() {
                new google.translate.TranslateElement({
                   pageLanguage: 'pl',
                   includedLanguages: 'en,cs,fr,de,sk,uk',
                   layout: google.translate.TranslateElement.InlineLayout.SIMPLE
                }, 'google_translate_element');
             }   
    JS
    );

          Requirements::javascript("//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit");

    I'm adding that alert() function works properly :/

  • sebastiankozub
    Avatar
    Community Member
    40 Posts

    Re: Google translate Link to this post

    I noticed that if I add:

    Requirements::javascript("//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit");

    silverstripe won't add this file to the html code,

    but if I add:

    Requirements::javascript("http://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit");

    silverstipe is adding it to html but in this form script does not work - I checked it on other pages ...
    it must begin with "//"

  • Martijn
    Avatar
    Community Member
    271 Posts

    Re: Google translate Link to this post

    Silverstripe won't add the file because if it does not contain http it will assume its a local file and if it can't find it, it will not include the file.

    I never used this script, but I can't imagine you have to use //scriptfile to include an external file.

    Maybe a bummer, but make sure you read some docs about the api. There are some examples on the web and as far as I can see you need a Google API key as well to use the translate script.

  • sebastiankozub
    Avatar
    Community Member
    40 Posts

    Re: Google translate Link to this post

    there's a code on the http://translate.google.com/translate_tools
    that simply adds nice button to translate page. It works well on other pages. Is there a way to overwrite Requirements::javascript() function that allows me to include "//.." files. Where I can find this function - I dom't know Sapphire Framework.

    <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>

  • sebastiankozub
    Avatar
    Community Member
    40 Posts

    Re: Google translate Link to this post

    Is there a way to overwrite Requirements::javascript() function that allows me to include "//.." files.
    Where I can find this function? - I don't know Sapphire Framework.

    8396 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.