Minibar: detect the language for show speech synthesis buttons in more cases

This was done to obtain speech synthesis for more languages in the Numerals
grammar, which uses neither language flags nor the standard naming for
concrete syntax.
This commit is contained in:
hallgren
2016-06-05 12:21:56 +00:00
parent 2320410d30
commit 773b2d8e16
2 changed files with 13 additions and 2 deletions

View File

@@ -29,10 +29,12 @@ var languages =
}()
var langname={}
var langcode={}
var langcode2={}
var langcode3={}
for(var i in languages) {
langname[languages[i].code]=languages[i].name
langcode[languages[i].name]=languages[i]
langcode2[languages[i].code]=languages[i].code2
langcode3[languages[i].code2]=languages[i].code
}

View File

@@ -69,11 +69,20 @@ function supportsSVG() {
function speech_buttons(to3,to2,txt) {
var voices = window.speechSynthesis && window.speechSynthesis.getVoices() || []
var dvs = voices.filter(function(v){return v.default})
function pick2dash(v) { return hasPrefix(v.lang,to2dash) }
if(to2)
var pick=function (v) { return v.lang==to2 }
else {
else if(to3.length==3) {
var to2dash=alangcode(to3)+"-"
var pick=function(v) { return hasPrefix(v.lang,to2dash) }
var pick=pick2dash
}
else {
// Maybe the name of the concrete syntax is the name of the language
// like in Numerals.pgf
var lang=to3.substr(0,1).toUpperCase()+to3.substr(1).toLowerCase()
var codes=langcode[lang]
var to2dash=(codes ? codes.code2 : to3)+"-"
var pick=pick2dash
}
function btn(v) {
var u=new SpeechSynthesisUtterance(txt)