diff options
| author | hallgren <hallgren@chalmers.se> | 2015-09-02 14:44:30 +0000 |
|---|---|---|
| committer | hallgren <hallgren@chalmers.se> | 2015-09-02 14:44:30 +0000 |
| commit | 0449784427a165653e1f684e029d6eccc9074870 (patch) | |
| tree | db97250c4f68ec475bb0b645ef68cd19480479c5 /src | |
| parent | 66454d844aba7eccb97c8561397c947af249d4ae (diff) | |
Wide coverage translation demo: make it easier to use with different grammars
Diffstat (limited to 'src')
| -rw-r--r-- | src/www/js/wc.js | 56 | ||||
| -rw-r--r-- | src/www/wc.html | 5 |
2 files changed, 37 insertions, 24 deletions
diff --git a/src/www/js/wc.js b/src/www/js/wc.js index 03d0d2140..2cd19e289 100644 --- a/src/www/js/wc.js +++ b/src/www/js/wc.js @@ -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() diff --git a/src/www/wc.html b/src/www/wc.html index 3251b0925..e2ed961bf 100644 --- a/src/www/wc.html +++ b/src/www/wc.html @@ -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> |
