summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhallgren <hallgren@chalmers.se>2012-09-17 15:58:40 +0000
committerhallgren <hallgren@chalmers.se>2012-09-17 15:58:40 +0000
commitdecefce6bc1c6a04c9ed45075453e7633ead97f2 (patch)
treeee753f420e5762bfdb2063026b9e9d96e644a137
parentfa3c87fb64675bece8fac08de1d243ef4595bafc (diff)
simple translator: accept DOS, Mac and Unix line breaks when importing text
-rw-r--r--src/www/translator/translator.js11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/www/translator/translator.js b/src/www/translator/translator.js
index c7b6cea04..0dfd5126e 100644
--- a/src/www/translator/translator.js
+++ b/src/www/translator/translator.js
@@ -483,7 +483,7 @@ Translator.prototype.import=function(el) {
}
function done() {
function add_segments(text) {
- var ls=text.split("\n")
+ var ls=lines(text)
var segs= punct.firstChild.checked
? split_punct(text,punctchars.value)
: paras.firstChild.checked
@@ -571,7 +571,7 @@ Translator.prototype.import_globalsight=function(el) {
}
function done() {
function import_text(name,text) {
- var ls=text.split("\n")
+ var ls=lines(text)
if(ls.length>0 && ls[0]=="# GlobalSight Download File") {
t.current=null;
t.local.put("current",null)
@@ -973,6 +973,13 @@ function split_punct(text,punct) {
return segs
}
+// Break a string into lines
+function lines(text) {
+ var ls=text.split("\r\n") // DOS
+ if(ls.length<=1) ls=text.split(/\n|\r/) // Unix | Mac
+ return ls
+}
+
function supports_local_files() {
// See http://www.html5rocks.com/en/tutorials/file/dndfiles/
return window.File && window.FileList && window.FileReader