diff options
| author | hallgren <hallgren@chalmers.se> | 2012-09-11 14:30:09 +0000 |
|---|---|---|
| committer | hallgren <hallgren@chalmers.se> | 2012-09-11 14:30:09 +0000 |
| commit | 8f85daa94ae72a85b83f42466efc7f393b6c693c (patch) | |
| tree | 54eeebb0869b8b39db3bd9f5c54389d65692e5d9 /src | |
| parent | 0cc0a03ac94546b5fd1855f06bb50ca4b232d2a5 (diff) | |
simple translator: export GlobalSight Download Files
TODO: consider using a better way to save to a local file
Diffstat (limited to 'src')
| -rw-r--r-- | src/www/translator/translator.js | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/src/www/translator/translator.js b/src/www/translator/translator.js index 50576b690..c7b6cea04 100644 --- a/src/www/translator/translator.js +++ b/src/www/translator/translator.js @@ -538,6 +538,30 @@ Translator.prototype.import=function(el) { if(t.current!="/") setTimeout(imp,100) } +Translator.prototype.export_globalsight=function() { + t=this + + /* + Taken from this discussion on saving to local files: + http://stackoverflow.com/questions/2897619/using-html5-javascript-to-generate-and-save-a-file + */ + open("data:application/octet-stream," + +encodeURIComponent(export_globalsight_download_file(t.document)), + t.document.name + /*,'toolbar=no,location=no,status=no'*/); + +/* + Also consider: FileSaver saveAs() + + Not directly support in browsers: + http://www.w3.org/TR/file-writer-api/#the-filesaver-interface + + Alternative implementation: FileSaver.js: + https://github.com/eligrey/FileSaver.js + http://eligrey.com/blog/post/saving-generated-files-on-the-client-side +*/ +} + Translator.prototype.import_globalsight=function(el) { hide_menu(el); var t=this @@ -704,7 +728,11 @@ Translator.prototype.draw_document=function() { var doc=t.document var o=doc.options; function draw_globalsight() { - return text(doc.globalsight ? " (from GlobalSight)" : "") + function gs_export() { t.export_globalsight(); } + return doc.globalsight + ? wrap("span",[text(" (from GlobalSight) "), + button("Export",gs_export)]) + : text("") } var hdr=wrap("h2",[text(doc.name),text(" "), wrap("small",[draw_translation(o),draw_globalsight()])]) @@ -992,6 +1020,20 @@ function import_globalsight_download_file(ls) { return doc; } +function export_globalsight_download_file(doc) { + var ls=[].concat(doc.globalsight.header) + + var gs=doc.globalsight.segments + var ss=doc.segments + for(var i=0;i<gs.length && i<ss.length;i++) + ls=ls.concat(gs[i],ss[i].target) + + ls.push("") + ls.push("# END GlobalSight Download File") + ls.push("") + return ls.join("\n") +} + /* --- Cloud Support -------------------------------------------------------- */ |
