-
FEATURED COMPONENTS
First time here? Check out the FAQ!
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
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);
:-)
Thanks gekkio, you make my day.
The sources are comitted as a new Dashboard module for zksample2
Many many thanks
Stephan
Asked: 2011-06-07 09:34:09 +0800
Seen: 239 times
Last updated: Jun 07 '11