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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

Google translate


Go to End


6 Posts   10322 Views

Avatar
frabraha

Community Member, 49 Posts

12 April 2010 at 9:45pm

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

Community Member, 59 Posts

24 October 2010 at 8:42pm

Edited: 24/10/2010 9:35pm

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

Community Member, 59 Posts

24 October 2010 at 9:59pm

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

Community Member, 271 Posts

25 October 2010 at 12:55am

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

Community Member, 59 Posts

25 October 2010 at 1:42am

Edited: 25/10/2010 10:04am

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

Community Member, 59 Posts

27 October 2010 at 7:45am

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.