/*---Translations对象--------------------------------------------------*/var tree_icon=“../minibar/tree-btn.png”;var alignment_icon=“../minibar/align-btn.png”;函数转换(服务器、opts){this.server=服务器;//选项的默认值:this.选项={show_abstract:错误,abstract_action:null,//选择抽象语法树时的操作show_trees:false,//添加按钮以显示抽象语法树,//解析树和单词对齐tree_img_format:支持SVG()?“svg”:“png”,//树木和路线图像的格式,//可以是“gif”、“png”或“svg”show_grouped_translations:true,to_multiple:true,//允许选择多个目标语言show_bracks:false,//显示带括号的字符串语音:true,//启用语音合成按钮translate_limit:25//要检索的最大解析树数}//应用提供的选项if(opts)for(opts中的var o)this.options[o]=opts[o];this.main=空(“div”);this.menus=空(“span”);var tom_opts={id:“to_menu”}if(this.options.to_multiple)tom_opts.multiple=true,tom_opt.size=8,tom_opts.style=“位置:绝对”;var tom=this.to_menu=节点(“选择”,tom_opts,[]);if(this.options.to_multiple){tom.style.display=“无”函数toggle_tom(){tom.style.display=tom.style.display==“无”?“”:“无”}appendChildren(this.menus,[按钮(“To:”,toggle_tom),汤姆,文本(“…”)])}else appendChildren(this.menus,[text(“To:”),tom])tom.onchange=绑定(this.change_language,this);var o=本选项if(o.initial_grammar&&o.inital_toLangs)this.set_toLangs_for(o.initial_grammar,o.initart_toLangs)/*//这似乎触发了Firefox和Chrome中奇怪的滚动行为:tom.onmouseover=函数(){var n=tom.options.length;tom.size=n<12?编号:12;}tom.onmouseout=函数(){var n=tom.options.length;tom.size=n<4?n:4;}*/}Translations.prototype.change_grammar=函数(语法){var t=这个t.grammar=语法;t.local=mt_local(t.server.current_grammar_url)更新语言菜单(t.to_menu,语法);insertFirst(t.to_menu,选项(“全部”,“全部”);t.to_menu.value=“全部”;var toLangs=t.local.get(“toLangs”)if(toLangs&&toLangs.length>0){t.toLangs=toLangst.toSet=toSet(toLangs)更新多功能表(t.to_menu,toLangs)}其他{t.toLangs=[“全部”]t.toSet={“全部”:true}}}Translations.prototype.clear=函数(){this.main.innerHTML=“”;}Translations.prototype.set_toLangs_for=函数(grammar_url,toLangs){var-local=mt_local(语法url)local.put(“toLangs”,toLangs)}Translations.prototype.change_language=函数(){var t=这个t.toLangs=多菜单选择(t.to_menu)t.toSet=toSet(t.toLangs)t.local.put(“toLangs”,t.toLangs)t.获取翻译();}Translations.prototype.translateFrom=函数(current,startcat,lin_action){this.current=当前;this.startcat=startcat;this.linaction=linaction;this.get_translations();}Translations.prototype.get_Translations=函数(){用(这个){var c=电流;var args={from:c.from,输入:gfunlex(c.input),cat:startcat}if(options.translate_limit)args.limit=选项.translate_limitif(选项.show_grouped_translations)server.translategroup(参数,绑定(showgroupedtranslations,this));其他的server.translate(参数,绑定(show_translations,this));}}Translations.prototype.target_lang=函数(){with(this)返回langpart(tomenu.value,grammar.name);}Translations.prototype.show_Translations=函数(translationResults){var self=此;函数abs_tdt(树){var as=self.options.show_trees? [self.abstree_button(树),self.alignment_button(树,to==“All”,self.toLangs),文本(“”)]: []as.push(文本(树))返回td(as)}函数text_speech(langcode,to,txt,lin){var langcode2=langCode(self.glagram,to)回绕(“span”,[txt,speech_buttons(langcode,langcode2,lin)])}函数lin_tdt(树,to,语言码,lin){var txt=换行(“span”,文本(“▸”+lin))var ts=文本语言(langcode,to,txt,lin)var as=wrap(“span”,自选项显示树? [self.parsetree_button(树,to,self.grammer),文本(“”),ts]:[ts])as.active=文本as.swap=ts返回为}功能动作(lin){返回self.lin_action?function(){self.lin_action(lin)}:null}函数atext(s,act){var txt=换行(“span”,文本)txt.onclick=行动返回txt}函数show_lin(语言代码,lin,树){函数draw_table(lintable,action){函数draw_texts(文本){函数文本1{var txt=atext(s,动作)返回换行符(“div”,text_speech(langcode,lin.to,txt,s))}返回texts.map(text1)}函数draw_row(行){return tr([td(atext(row.params,action)),td(draw_texts(row.texts))])} // ▼ ▾回绕(“span”,[atext(“▾”,动作),wrap_class(“表”,“lintable”,lintable.map(draw_row))]}函数get_tabular(){函数show_table(lins){if(lins.length==1){函数restore(){replaceNode(one.swap,all)}var all=draw_table(lins[0].table,恢复)replaceNode(全部,一个.swap)one.active.onclick=function(){replaceNode(all,one.swap)}}}self.server.pgf_call(“linearizeTable”,{“tree”:树,“to”:lin.to},show_table)}var one=lin_tdt(树,lin.to,语言码,lin.text)//one.active.onclick=获取选项卡返回td(一)}带(自我){var trans=主;//var到=目标长度();//错误的var to=to _枚举值;var toLangs=自.to语言var to设置=self.to设置var cnt=translationResults.length;//通常cnt==1//trans.translations=翻译;trans.single_translation=[];trans.innerHTML=“”;/*trans.appendChild(换行(“h3”,文本(cnt<1?“无翻译?”:碳纳米管>1?“”+cnt+“翻译:”:“一个翻译:”));*/对于(var p=0;p1) tbody.appendChild(tr([td(文本(lin[i].tree))]);}trans.appendChild(wrap(“table”,tbody));}}}}Translations.prototype.abstree_button=函数(abs){var f=this.options.tree_img_format;var img=this.server.current_grammar_url+“?command=abtrtree&format=”+f+“&tree=”+编码URI组件(abs)var btn=树按钮(img,“&nocat=true”);btn.title=“单击以显示抽象语法树”返回btn}Translations.prototype.alignment_button=函数(abs,all,toLangs){var f=this.options.tree_img_format;var i=button_img(对齐图标,函数(){切换图标(i)});var to=全部?“”:“&to=”+encodeURI组件(toLangs.join(“”))i.title=“单击以显示单词对齐方式”i.other=this.server.current_grammar_url+“?command=alignment&format=”+f+“&tree=”+encodeURIComponent(abs)+to;返回i;}Translations.prototype.parsetree_button=函数(abs,lang,grammar){var f=this.options.tree_img_format;var img=此服务器当前语法url+“?command=parsetree&format=”+f+“&nodep=true&nodefont=arial”+“&from=”+lang+“&tree=”+encodeURIComponent(abs);var img_nofun=img+“&nofun=true”var help=“再次单击显示解析树。再次单击显示函数名。”if(f==“svg”&&grammar.hasDependencyLabels){var defimg=this.server.current_grammar_url+“?command=deptree&format=svg&to=”+lang+“&tree=”+编码URI组件(abs);var imgs=[tree_icon,defimg,img_nofun,img]help=“单击以显示依赖关系树。”+help}else变量imgs=[tree_icon,img_nofun,img]var btn=循环图像(img)btn.title=帮助返回btn;}/*---辅助功能--------------------------------------------------*/函数mt_local(grammar_url){return appLocalStorage(“gf.minibar_translations.”+grammar_url+“.”)}函数树按钮(img_url,opt){返回cycle_images([tree_icon,img_url+(opt||“&nofun=true”),img_ url])}函数draw_bracks(b){返回b.token? span_class(“标记”,文本(b.token)):节点(“span”,{“class”:“括号”,标题:(b.fun | |“_”)+“:”+b.cat+“”+b.fid+“:“+b.index},b.儿童地图(draw_barks)}函数draw_brackss(bs){return数组.isArray(bs)? bs.map(draw_barks)//在某些情况下gf>3.5:牵引架(bs)//gf≤3.5}