1
0
forked from GitHub/gf-core

Cloud service & apps: better error handling in wide coverage translation

The wide coverage demo apps now shows a "please wait" message while the grammar
is loading, and a red error message if the grammar is not found on the server.
The Simple Translation Tool also show red error messages if the grammar is not
found.
This commit is contained in:
hallgren
2014-06-20 18:39:28 +00:00
parent 78ccefc4f4
commit eee9617036
4 changed files with 43 additions and 16 deletions

View File

@@ -3,10 +3,12 @@ wc.cnl="Phrasebook" // try this controlled natural language first
wc.f=document.forms[0]
wc.o=element("output")
wc.e=element("extra")
wc.i=element("grammarinfo")
wc.p=element("pick")
wc.os=[] // output segment list
wc.cache={} // output segment cache, indexed by source text
wc.local=appLocalStorage("gf.wc.")
wc.translating=""
wc.delayed_translate=function() {
function restart(){ if(wc.f.input.value!=wc.translating) wc.translate() }
@@ -298,6 +300,7 @@ wc.try_google=function() {
// Update language selection menus with the languages supported by the grammar
function init_languages() {
function init2(langs) {
replaceInnerHTML(wc.i,"Enter text to translate above")
wc.languages=langs
var langset=toSet(langs)
function update_menu(m) {
@@ -310,7 +313,13 @@ function init_languages() {
update_menu(wc.f.from)
update_menu(wc.f.to)
}
gftranslate.get_languages(init2)
function initerror(errortext,status,ct) {
var msg = status==404 ? "The wide cover translation grammar was not found on the server" : "Server problem "+status
replaceChildren(wc.i,text(msg))
if(wc.i) wc.i.className="error"
}
replaceInnerHTML(wc.i,"Loading the wide coverage translation grammar, please wait...")
gftranslate.get_languages(init2,initerror)
}
function init_speech() {