Wide coverage translation demo: make it easier to use with different grammars

This commit is contained in:
hallgren
2015-09-02 14:44:30 +00:00
parent 66454d844a
commit 0449784427
2 changed files with 37 additions and 24 deletions

View File

@@ -15,7 +15,6 @@ wc.os=[] /* output segment list
current_pick::Int // index into rs or -1
}] */
wc.cache={} // output segment cache, indexed by source text
wc.local=appLocalStorage("gf.wc.")
wc.translating=""
wc.delayed_translate=function() {
@@ -37,21 +36,25 @@ wc.clear=function() {
}
wc.save=function() {
var f=wc.f
wc.local.put("from",f.from.value)
wc.local.put("to",f.to.value)
wc.local.put("input",f.input.value)
wc.local.put("colors",f.colors.checked)
if(wc.local) {
var f=wc.f
wc.local.put("from",f.from.value)
wc.local.put("to",f.to.value)
wc.local.put("input",f.input.value)
wc.local.put("colors",f.colors.checked)
}
}
wc.load=function() {
var f=wc.f
f.input.value=wc.local.get("input",f.input.value)
f.from.value=wc.local.get("from",f.from.value)
f.to.value=wc.local.get("to",f.to.value)
f.colors.checked=wc.local.get("colors",f.colors.checked)
wc.colors()
wc.delayed_translate()
if(wc.local) {
var f=wc.f
f.input.value=wc.local.get("input",f.input.value)
f.from.value=wc.local.get("from",f.from.value)
f.to.value=wc.local.get("to",f.to.value)
f.colors.checked=wc.local.get("colors",f.colors.checked)
wc.colors()
wc.delayed_translate()
}
}
wc.translate=function() {
@@ -381,7 +384,7 @@ wc.bracketsToD3=function(bs) {
}
// Update language selection menus with the languages supported by the grammar
function init_languages() {
wc.init_languages=function () {
function init2(langs) {
replaceInnerHTML(wc.i,"Enter text to translate above")
wc.languages=langs
@@ -405,7 +408,7 @@ function init_languages() {
gftranslate.get_languages(init2,initerror)
}
function init_speech() {
wc.init_speech=function() {
var speak=element("speak")
if(speak) {
wc.speech=window.speechSynthesis && window.speechSynthesis.getVoices().length>0
@@ -413,12 +416,19 @@ function init_speech() {
}
}
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.initialize=function(grammar_name,grammar_url) {
if(grammar_name && grammar_url) {
gftranslate.grammar=grammar_name
gftranslate.jsonurl=grammar_url
}
wc.init_languages()
//init_speech()
setTimeout(wc.init_speech,500) // A hack for Chrome.
if(wc.cnl) {
wc.pgf_online=pgf_online({});
wc.pgf_online.switch_grammar(wc.cnl+".pgf")
}
wc.local=appLocalStorage("gf.wc."+gftranslate.grammar+".")
wc.load()
wc.f.input.focus()
}
wc.load()
wc.f.input.focus()

View File

@@ -107,7 +107,7 @@ span.inflect { color: blue; }
</div>
<hr>
<div class=modtime><small>
<!-- hhmts start -->Last modified: Wed May 27 15:27:37 CEST 2015 <!-- hhmts end -->
<!-- hhmts start -->Last modified: Wed Sep 2 16:12:49 CEST 2015 <!-- hhmts end -->
</small></div>
<a href="http://www.grammaticalframework.org/demos/translation.html">About</a>
<script src="js/support.js"></script>
@@ -117,6 +117,9 @@ span.inflect { color: blue; }
<script src="js/pgf_online.js"></script>
<script src="minibar/minibar_support.js">/* speech functions */</script>
<script src="js/wc.js"></script>
<script>
wc.initialize()
</script>
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script src="http://d3js.org/d3.v3.min.js"></script>