var wc={} wc.cnl="Phrasebook" // try this controlled natural language first wc.f=document.forms[0] wc.o=element("output") wc.e=element("extra") wc.p=element("pick") wc.serial=0 wc.os=[] wc.delayed_translate=function() { function restart(){ if(wc.f.input.value!=wc.translating) wc.translate() } if(wc.timer) clearTimeout(wc.timer); wc.timer=setTimeout(restart,500) var h=wc.f.input.scrollHeight,bh=document.body.clientHeight if(h>bh) h=bh if(wc.f.input.clientHeight" //else { replaceChildren(output,text("["+msg+"]")) output.className="error" } disable(false) } function show_pick(i) { return function() { show_trans(i); return false; } } function show_picks() { clear(p) for(var i=0;i"+r.tree if(wc.p /*&& rs.length>1*/) show_picks() //if(f.speak.checked) wc.speak(t.text,f.to.value) if(get_more) { var f=get_more get_more=null f() } } output.onclick=show_more function show_trans(i) { var r=rs[i] var t=trans_quality(r) replaceChildren(output,text(t.text)) wc.os[si].text=t.text output.className=t.quality current_pick=i if(selected==si) show_more() } function showit(r,text) { text=text.trimRight() rs.push(r) var j=rs.length-1 rs[j].text=text if(current_pick==j) show_trans(j) else if(selected==si) show_picks() disable(false) } function trans(text,i) { function step3(tra) { if(wc.serial==current) { if(tra.length>=1) { var r=tra[0] if(r.error!=undefined) show_error(tra[0].error) else if(r.linearizations) { r.text=r.linearizations[0].text unlextext(r.text,function(text){showit(r,text)}) if(wc.p && i<9) { if(si==selected) trans(text,i+1) else get_more=function() { trans(text,i+1) } } } else show_error("no linearizations") } else if(i==0) show_error("Unable to translate") } } gftranslate.translate(text,f.from.value,f.to.value,i,1,step3) } function step2(text) { trans(text,0) } function step2cnl(text) { function step3cnl(results) { var trans=results[0].translations if(trans && trans.length>=1) { var r=trans[0] r.text=r.linearizations[0].text r.prob=0 unlextext(r.text,function(text){showit(r,text)}) } step2(text) } wc.pgf_online.translate({from:wc.cnl+f.from.value, to:wc.cnl+f.to.value, input:text}, step3cnl, function(){step2(text)}) } lextext(is[si],wc.cnl ? step2cnl : step2) } wc.translating=f.input.value var is=wc.is=split_punct(wc.translating+"\n") for(var i=0;i0 if(wc.speech) speak.style.display="inline" } } init_languages() init_speech() setTimeout(init_speech,500) // A hack for Chrome. if(wc.cnl) { wc.pgf_online=pgf_online({}); wc.pgf_online.switch_grammar(wc.cnl+".pgf") } wc.f.input.focus()