forked from GitHub/gf-core
minibar: more work on speech output
This commit is contained in:
@@ -5,6 +5,20 @@ function langpart(conc,abs) { // langpart("FoodsEng","Foods") == "Eng"
|
|||||||
return hasPrefix(conc,abs) ? conc.substr(abs.length) : conc;
|
return hasPrefix(conc,abs) ? conc.substr(abs.length) : conc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Lookup language codes (from "flags language = ..." in the source grammar)
|
||||||
|
function langCode(grammar,conc) {
|
||||||
|
if(!grammar.langCode) {
|
||||||
|
var ls=grammar.languages
|
||||||
|
var langCode={}
|
||||||
|
for(var i=0;i<ls.length;i++)
|
||||||
|
if(ls[i].languageCode)
|
||||||
|
langCode[ls[i].name]=ls[i].languageCode
|
||||||
|
grammar.langCode=langCode
|
||||||
|
}
|
||||||
|
return grammar.langCode[conc]
|
||||||
|
}
|
||||||
|
|
||||||
// Words are separated by spaces (for now). GF has other lexers/unlexers.
|
// Words are separated by spaces (for now). GF has other lexers/unlexers.
|
||||||
function gf_lex(s) { return s.split(" "); }
|
function gf_lex(s) { return s.split(" "); }
|
||||||
function gf_unlex(ws) { return ws.join(" "); }
|
function gf_unlex(ws) { return ws.join(" "); }
|
||||||
|
|||||||
@@ -117,50 +117,60 @@ Translations.prototype.show_translations=function(translationResults) {
|
|||||||
as.push(text(tree))
|
as.push(text(tree))
|
||||||
return td(as)
|
return td(as)
|
||||||
}
|
}
|
||||||
function lin_tdt(tree,to,langcode,lin,action) {
|
function text_speech(langcode,to,txt,lin) {
|
||||||
var txt=text("▸ "+lin)
|
var langcode2=langCode(self.grammar,to)
|
||||||
if(action) {
|
return wrap("span",[txt,speech_buttons(langcode,langcode2,lin)])
|
||||||
txt=wrap("span",txt)
|
}
|
||||||
txt.onclick=action
|
function lin_tdt(tree,to,langcode,lin) {
|
||||||
}
|
var txt=wrap("span",text("▸ "+lin))
|
||||||
var tree_btn=self.parsetree_button(tree,to)
|
var ts = text_speech(langcode,to,txt,lin)
|
||||||
var as = self.options.show_trees
|
var as = wrap("span",
|
||||||
? [tree_btn,text(" ")]
|
self.options.show_trees
|
||||||
: []
|
? [self.parsetree_button(tree,to),text(" "),ts]
|
||||||
as.push(txt)
|
: [ts])
|
||||||
if(self.options.speech) as.push(speech_buttons(langcode,lin))
|
as.active=txt
|
||||||
return td(as)
|
as.swap=ts
|
||||||
|
return as
|
||||||
}
|
}
|
||||||
function act(lin) {
|
function act(lin) {
|
||||||
return self.lin_action ? function() { self.lin_action(lin) } : null
|
return self.lin_action ? function() { self.lin_action(lin) } : null
|
||||||
}
|
}
|
||||||
|
function atext(s,act) {
|
||||||
|
var txt=wrap("span",text(s))
|
||||||
|
txt.onclick=act
|
||||||
|
return txt
|
||||||
|
}
|
||||||
function show_lin(langcode,lin,tree) {
|
function show_lin(langcode,lin,tree) {
|
||||||
function draw_table(lintable) {
|
function draw_table(lintable,action) {
|
||||||
function draw_texts(texts) {
|
function draw_texts(texts) {
|
||||||
return texts.map(function(s) { return wrap("div",text(s)) })
|
function text1(s) {
|
||||||
|
var txt=atext(s,action)
|
||||||
|
return wrap("div",text_speech(langcode,lin.to,txt,s))
|
||||||
|
}
|
||||||
|
return texts.map(text1)
|
||||||
}
|
}
|
||||||
function draw_row(row) {
|
function draw_row(row) {
|
||||||
return tr([td(text(row.params)),td(draw_texts(row.texts))])
|
return tr([td(text(row.params)),td(draw_texts(row.texts))])
|
||||||
} // ▼ ▾
|
} // ▼ ▾
|
||||||
return wrap("span",
|
return wrap("span",
|
||||||
[text("▾ "),
|
[atext("▾ ",action),
|
||||||
wrap_class("table","lintable",lintable.map(draw_row))])
|
wrap_class("table","lintable",lintable.map(draw_row))])
|
||||||
}
|
}
|
||||||
function get_tabular() {
|
function get_tabular() {
|
||||||
var t=this
|
|
||||||
var pa=this.parentNode
|
|
||||||
function show_table(lins) {
|
function show_table(lins) {
|
||||||
if(lins.length==1) {
|
if(lins.length==1) {
|
||||||
var ta=draw_table(lins[0].table)
|
function restore() { replaceNode(one.swap,all) }
|
||||||
replaceNode(ta,t)
|
var all=draw_table(lins[0].table,restore)
|
||||||
ta.onclick=function() { replaceNode(t,ta) }
|
replaceNode(all,one.swap)
|
||||||
t.onclick=function() { replaceNode(ta,t) }
|
one.active.onclick=function() { replaceNode(all,one.swap) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.server.pgf_call("linearizeTable",{"tree":tree,"to":lin.to},
|
self.server.pgf_call("linearizeTable",{"tree":tree,"to":lin.to},
|
||||||
show_table)
|
show_table)
|
||||||
}
|
}
|
||||||
return lin_tdt(tree,lin.to,langcode,lin.text,get_tabular) // ▶
|
var one= lin_tdt(tree,lin.to,langcode,lin.text) // ▶
|
||||||
|
one.active.onclick=get_tabular
|
||||||
|
return td(one)
|
||||||
}
|
}
|
||||||
with(self) {
|
with(self) {
|
||||||
var trans=main;
|
var trans=main;
|
||||||
@@ -315,12 +325,14 @@ function supportsSVG() {
|
|||||||
return document.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#BasicStructure", "1.1")
|
return document.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#BasicStructure", "1.1")
|
||||||
}
|
}
|
||||||
|
|
||||||
function speech_buttons(to3,txt) {
|
function speech_buttons(to3,to2,txt) {
|
||||||
var to2=alangcode(to3)+"-"
|
|
||||||
var voices = window.speechSynthesis && window.speechSynthesis.getVoices() || []
|
var voices = window.speechSynthesis && window.speechSynthesis.getVoices() || []
|
||||||
var dvs = voices.filter(function(v){return v.default})
|
var dvs = voices.filter(function(v){return v.default})
|
||||||
function pick(v) {
|
if(to2)
|
||||||
return v.lang.substr(0,to2.length)==to2
|
var pick=function (v) { return v.lang==to2 }
|
||||||
|
else {
|
||||||
|
var to2dash=alangcode(to3)+"-"
|
||||||
|
var pick=function(v) { return hasPrefix(v.lang,to2dash) }
|
||||||
}
|
}
|
||||||
function btn(v) {
|
function btn(v) {
|
||||||
var u=new SpeechSynthesisUtterance(txt)
|
var u=new SpeechSynthesisUtterance(txt)
|
||||||
|
|||||||
Reference in New Issue
Block a user