From deccceaaaac1fdcaba8637e7befb9b1a34a8293f Mon Sep 17 00:00:00 2001 From: "Diego F.(EW7)" Date: Mon, 19 Dec 2016 17:12:29 -0300 Subject: [PATCH] =?UTF-8?q?Traducci=C3=B3n=20de=20throw=20Error(...).=20Cl?= =?UTF-8?q?ose=20#35?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/txt-to-sql.js | 22 +++++++++++++++------- web/txt-to-sql.js | 22 +++++++++++++++------- 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/lib/txt-to-sql.js b/lib/txt-to-sql.js index 445e259..7686bf8 100644 --- a/lib/txt-to-sql.js +++ b/lib/txt-to-sql.js @@ -239,17 +239,17 @@ function processEncodingOptions(info) { var inFromToString = info.rawTable.toString("utf8"); if(info.opts.inputEncoding==='ANSI') { if(inFromToString.substr(1).indexOf('\uFFFD')<0) { - throw new Error('ansi -> utf8: replacement character not found'); + throw new Error(info.messages.errConvRep); } info.decodedBuffer = iconv.decode(info.rawTable, "win1252"); if(compareBuffers(info.decodedBuffer, info.rawTable) === -1) { - throw new Error('ansi -> utf8: no conversion performed'); + throw new Error(info.messages.errConv); } } else if(info.opts.inputEncoding==='UTF8') { info.decodedBuffer = inFromToString; var result = compareBuffers(info.rawTable, new Buffer(info.decodedBuffer, 'utf8')); if(result !== -1) { - throw new Error('utf8 check failed in position: '+result); + throw new Error(txtToSql.errString(info, 'errUTF',[result])); } } else { info.decodedBuffer = inFromToString; @@ -272,7 +272,7 @@ function determineSeparator(info){ return info.headers.split(separator).length>1; }); if(separatorCandidates.length<=0){ - throw new Error('no separator detected'); + throw new Error(info.messages.errSeparator); } info.opts.separator=separatorCandidates[0]; } @@ -334,9 +334,7 @@ function separateColumns(info){ info.columnsInfo = info.delimiter ? separateWithDelimiter(info) : separateWithSeparator(info); if(info.opts.columns && 'name' in info.opts.columns[0]) { if(info.opts.columns.length !== info.columnsInfo.length) { - throw new Error('wrong number of column names: expected '+ - info.columnsInfo.length+ - ', obtained '+info.opts.columns.length); + throw new Error(txtToSql.errString(info, 'errNumCols',[info.columnsInfo.length,info.opts.columns.length])); } info.columnsInfo.forEach(function(column, index) { column.name = info.opts.columns[index].name; @@ -756,6 +754,11 @@ txtToSql.dictionary={ errBadRowMulti:'row multiline #$1~#$2 has $3 fields, should have $4', errColMissing:"missing name for column #$1", errColDupli:"duplicated column name '$1'", + errConvRep:'ansi -> utf8: replacement character not found', + errConv:'ansi -> utf8: no conversion performed', + errUTF:'utf8 check failed in position: $1', + errSeparator:'no separator detected', + errNumCols:'wrong number of column names: expected $1, obtained $2', }, es:{ row:'registro', @@ -774,6 +777,11 @@ txtToSql.dictionary={ errBadRowMulti:'registro multilínea #$1~#$2 tiene $3 campos, debería tener $4', errColMissing:"falta nombre para la columna #$1", errColDupli:"nombre de columna duplicado '$1'", + errConvRep:'ansi -> utf8: caracter de reemplazo no encontrado', + errConv:'ansi -> utf8: no se realizó la conversión', + errUTF:'verificación utf8 falló en la posición: $1', + errSeparator:'no se detectó el separador', + errNumCols:'número de nombres de columna incorrecto: esperados $1, recibidos $2', } }; diff --git a/web/txt-to-sql.js b/web/txt-to-sql.js index 445e259..7686bf8 100644 --- a/web/txt-to-sql.js +++ b/web/txt-to-sql.js @@ -239,17 +239,17 @@ function processEncodingOptions(info) { var inFromToString = info.rawTable.toString("utf8"); if(info.opts.inputEncoding==='ANSI') { if(inFromToString.substr(1).indexOf('\uFFFD')<0) { - throw new Error('ansi -> utf8: replacement character not found'); + throw new Error(info.messages.errConvRep); } info.decodedBuffer = iconv.decode(info.rawTable, "win1252"); if(compareBuffers(info.decodedBuffer, info.rawTable) === -1) { - throw new Error('ansi -> utf8: no conversion performed'); + throw new Error(info.messages.errConv); } } else if(info.opts.inputEncoding==='UTF8') { info.decodedBuffer = inFromToString; var result = compareBuffers(info.rawTable, new Buffer(info.decodedBuffer, 'utf8')); if(result !== -1) { - throw new Error('utf8 check failed in position: '+result); + throw new Error(txtToSql.errString(info, 'errUTF',[result])); } } else { info.decodedBuffer = inFromToString; @@ -272,7 +272,7 @@ function determineSeparator(info){ return info.headers.split(separator).length>1; }); if(separatorCandidates.length<=0){ - throw new Error('no separator detected'); + throw new Error(info.messages.errSeparator); } info.opts.separator=separatorCandidates[0]; } @@ -334,9 +334,7 @@ function separateColumns(info){ info.columnsInfo = info.delimiter ? separateWithDelimiter(info) : separateWithSeparator(info); if(info.opts.columns && 'name' in info.opts.columns[0]) { if(info.opts.columns.length !== info.columnsInfo.length) { - throw new Error('wrong number of column names: expected '+ - info.columnsInfo.length+ - ', obtained '+info.opts.columns.length); + throw new Error(txtToSql.errString(info, 'errNumCols',[info.columnsInfo.length,info.opts.columns.length])); } info.columnsInfo.forEach(function(column, index) { column.name = info.opts.columns[index].name; @@ -756,6 +754,11 @@ txtToSql.dictionary={ errBadRowMulti:'row multiline #$1~#$2 has $3 fields, should have $4', errColMissing:"missing name for column #$1", errColDupli:"duplicated column name '$1'", + errConvRep:'ansi -> utf8: replacement character not found', + errConv:'ansi -> utf8: no conversion performed', + errUTF:'utf8 check failed in position: $1', + errSeparator:'no separator detected', + errNumCols:'wrong number of column names: expected $1, obtained $2', }, es:{ row:'registro', @@ -774,6 +777,11 @@ txtToSql.dictionary={ errBadRowMulti:'registro multilínea #$1~#$2 tiene $3 campos, debería tener $4', errColMissing:"falta nombre para la columna #$1", errColDupli:"nombre de columna duplicado '$1'", + errConvRep:'ansi -> utf8: caracter de reemplazo no encontrado', + errConv:'ansi -> utf8: no se realizó la conversión', + errUTF:'verificación utf8 falló en la posición: $1', + errSeparator:'no se detectó el separador', + errNumCols:'número de nombres de columna incorrecto: esperados $1, recibidos $2', } };