0

need help by java created/calls js

asked 2011-06-07 09:34:09 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

updated 2011-06-07 09:56:05 +0800

Hi all,

i have a try to integrate a google translation for the website. If i put the few html codes in a zul file it works well.
My problem is to create the same in pure java.
zk 5.0.7.1

<zk xmlns="http://www.zkoss.org/2005/zul"
	xmlns:h="http://www.w3.org/1999/xhtml"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.zkoss.org/2005/zul http://www.zkoss.org/2005/zul/zul.xsd">


	<window id="startWindow" border="none" width="800px"
		height="500px">


		<!-- Google Translate Element -->
		<h:div id="google_translate_element" style="display:block">
		</h:div>
		<h:script>
			function googleTranslateElementInit() { new
			google.translate.TranslateElement({pageLanguage: "af"},
			"google_translate_element"); };
		</h:script>
		<h:script	src="http://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit">
		</h:script>



		<separator height="50px" />
		<label value="This is a test string for translating."	style="color: blue; font-weight: bold;" />


	</window>
</zk>


don't get it to work:

		win.appendChild(new Html("<h:div id='google_translate_element' style='display:block'></h:div>"));
		win.appendChild(new Html("<h:script> function googleTranslateElementInit() { new google.translate.TranslateElement({pageLanguage: 'af'}, 'google_translate_element'); }; </h:script>"));
		win.appendChild(new Html("<h:script src='http://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit'></h:script>"));

thanks
Stephan

delete flag offensive retag edit

2 Replies

Sort by ยป oldest newest

answered 2011-06-07 10:37:14 +0800

gekkio gravatar image gekkio flag of Finland
899 1
http://gekkio.fi/blog

Try this:

Div container = new Div();
win.appendChild(container);

Script init = new Script();
init.setContent("function googleTranslateElementInit() { new google.translate.TranslateElement({pageLanguage: 'af'}, '" + container.getUuid() + "'); };");
win.appendChild(init);

Script translate = new Script();
translate.setSrc("http://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit");
win.appendChild(translate);

link publish delete flag offensive edit

answered 2011-06-07 11:15:17 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

:-)

Thanks gekkio, you make my day.

The sources are comitted as a new Dashboard module for zksample2


Many many thanks
Stephan

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2011-06-07 09:34:09 +0800

Seen: 239 times

Last updated: Jun 07 '11

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More