Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions

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

Google translate


Reply

6 Posts   8425 Views

Avatar
frabraha

12 April 2010 at 9:45pm Community Member, 49 Posts

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?

Avatar
sebastiankozub

24 October 2010 at 8:42pm (Last edited: 24 October 2010 9:35pm), Community Member, 40 Posts

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

Avatar
sebastiankozub

24 October 2010 at 9:59pm Community Member, 40 Posts

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

Avatar
Martijn

25 October 2010 at 12:55am Community Member, 271 Posts

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.

Avatar
sebastiankozub

25 October 2010 at 1:42am (Last edited: 25 October 2010 10:04am), Community Member, 40 Posts

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>

Avatar
sebastiankozub

27 October 2010 at 7:45am Community Member, 40 Posts

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.