Merge pull request #55 from strongloop/initial_glob

Add globalization
This commit is contained in:
Candy 2016-07-27 17:29:42 -04:00 committed by GitHub
commit cc8809a230
6 changed files with 45 additions and 15 deletions

3
.gitignore vendored
View File

@ -13,3 +13,6 @@
node_modules node_modules
checkstyle.xml checkstyle.xml
loopback-connector-*.tgz loopback-connector-*.tgz
!intl/
intl/*
!intl/en/

View File

@ -3,6 +3,9 @@
// This file is licensed under the MIT License. // This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT // License text available at https://opensource.org/licenses/MIT
var SG = require('strong-globalize');
SG.SetRootDir(__dirname);
exports.Connector = require('./lib/connector'); exports.Connector = require('./lib/connector');
// Set up SqlConnector as an alias to SQLConnector // Set up SqlConnector as an alias to SQLConnector
exports.SQLConnector = exports.SqlConnector = require('./lib/sql'); exports.SQLConnector = exports.SqlConnector = require('./lib/sql');

15
intl/en/messages.json Normal file
View File

@ -0,0 +1,15 @@
{
"8dc8fd7cc38a39896c03663cca38aad5": "execute() must be implemented by the connector",
"06c539e08213828e62e7f5339fb255ec": "{{getPlaceholderForValue()}} must be implemented by the connector",
"2b051e39b1efd1f2106b155495087b0f": "id value is required",
"30a4fa7fc115109b8cd096d895e9869e": "{{getPlaceholderForIdentifier()}} must be implemented by the connector",
"4cbf9bb7e7347b86c1dba4e54163c4ea": "{{getCountForAffectedRows()}} must be implemented by the connector",
"871b10e82a2dc1d0659571c5dee8fa95": "{{executeSQL()}} must be implemented by the connector",
"956ede286087599213bc112b5a76408b": "{{applyPagination()}} must be implemented by the connector",
"bca74e4fbb2859c22381fb531a0f896d": "{{getInsertedId()}} must be implemented by the connector",
"c491cd5577a54bf265d407ddaa20ffcb": "{{escapeValue()}} must be implemented by the connector",
"e54d944c2a2c85a23caa86027ae307cf": "Cannot migrate models not attached to this datasource: {0}",
"f3e021460b7a6f5991fca890b786a11b": "{{escapeName()}} must be implemented by the connector",
"fe1c27354af9f4c88bf9c1d246e41230": "{{toColumnValue()}} must be implemented by the connector",
"fe914555563f5f566adfc0c5db8445db": "{{fromColumnValue()}} must be implemented by the connector"
}

View File

@ -3,6 +3,8 @@
// This file is licensed under the MIT License. // This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT // License text available at https://opensource.org/licenses/MIT
var SG = require('strong-globalize');
var g = SG();
var debug = require('debug')('loopback:connector'); var debug = require('debug')('loopback:connector');
module.exports = Connector; module.exports = Connector;
@ -80,7 +82,7 @@ Connector.prototype.getMetadata = function() {
* @param {Function} [callback] The callback function * @param {Function} [callback] The callback function
*/ */
Connector.prototype.execute = function(command, params, options, callback) { Connector.prototype.execute = function(command, params, options, callback) {
throw new Error('execute() must be implemented by the connector'); throw new Error(g.f('execute() must be implemented by the connector'));
}; };
/** /**

View File

@ -3,6 +3,9 @@
// This file is licensed under the MIT License. // This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT // License text available at https://opensource.org/licenses/MIT
var SG = require('strong-globalize');
var g = SG();
var util = require('util'); var util = require('util');
var async = require('async'); var async = require('async');
var assert = require('assert'); var assert = require('assert');
@ -1229,7 +1232,7 @@ Connector.defineAliases(SQLConnector.prototype, 'all', ['findAll']);
SQLConnector.prototype.find = function(model, id, options, cb) { SQLConnector.prototype.find = function(model, id, options, cb) {
if (id == null) { if (id == null) {
process.nextTick(function() { process.nextTick(function() {
var err = new Error('id value is required'); var err = new Error(g.f('id value is required'));
if (cb) { if (cb) {
cb(err); cb(err);
} }
@ -1329,8 +1332,8 @@ SQLConnector.prototype.automigrate = function(models, cb) {
}); });
if (invalidModels.length) { if (invalidModels.length) {
return process.nextTick(function() { return process.nextTick(function() {
cb(new Error('Cannot migrate models not attached to this datasource: ' + cb(new Error(g.f('Cannot migrate models not attached to this datasource: %s',
invalidModels.join(' '))); invalidModels.join(' '))));
}); });
} }
@ -1398,7 +1401,7 @@ SQLConnector.prototype.escapeObject = function(obj) {
* *
*/ */
SQLConnector.prototype.toColumnValue = function(propertyDef, value) { SQLConnector.prototype.toColumnValue = function(propertyDef, value) {
throw new Error('toColumnValue() must be implemented by the connector'); throw new Error(g.f('{{toColumnValue()}} must be implemented by the connector'));
}; };
/** /**
@ -1408,7 +1411,7 @@ SQLConnector.prototype.toColumnValue = function(propertyDef, value) {
* @returns {*} Model property value * @returns {*} Model property value
*/ */
SQLConnector.prototype.fromColumnValue = function(propertyDef, value) { SQLConnector.prototype.fromColumnValue = function(propertyDef, value) {
throw new Error('fromColumnValue() must be implemented by the connector'); throw new Error(g.f('{{fromColumnValue()}} must be implemented by the connector'));
}; };
/** /**
@ -1417,7 +1420,7 @@ SQLConnector.prototype.fromColumnValue = function(propertyDef, value) {
* @returns {String} An escaped name for SQL * @returns {String} An escaped name for SQL
*/ */
SQLConnector.prototype.escapeName = function(name) { SQLConnector.prototype.escapeName = function(name) {
throw new Error('escapeName() must be implemented by the connector'); throw new Error(g.f('{{escapeName()}} must be implemented by the connector'));
}; };
/** /**
@ -1426,7 +1429,7 @@ SQLConnector.prototype.escapeName = function(name) {
* @returns {*} An escaped value for SQL * @returns {*} An escaped value for SQL
*/ */
SQLConnector.prototype.escapeValue = function(value) { SQLConnector.prototype.escapeValue = function(value) {
throw new Error('escapeValue() must be implemented by the connector'); throw new Error(g.f('{{escapeValue()}} must be implemented by the connector'));
}; };
/** /**
@ -1435,7 +1438,8 @@ SQLConnector.prototype.escapeValue = function(value) {
* @returns {String} The place holder * @returns {String} The place holder
*/ */
SQLConnector.prototype.getPlaceholderForIdentifier = function(key) { SQLConnector.prototype.getPlaceholderForIdentifier = function(key) {
throw new Error('getPlaceholderForIdentifier() must be implemented by the connector'); throw new Error(g.f('{{getPlaceholderForIdentifier()}} must be implemented by ' +
'the connector'));
}; };
/** /**
@ -1444,7 +1448,8 @@ SQLConnector.prototype.getPlaceholderForIdentifier = function(key) {
* @returns {String} The place holder * @returns {String} The place holder
*/ */
SQLConnector.prototype.getPlaceholderForValue = function(key) { SQLConnector.prototype.getPlaceholderForValue = function(key) {
throw new Error('getPlaceholderForValue() must be implemented by the connector'); throw new Error(g.f('{{getPlaceholderForValue()}} must be implemented by ' +
'the connector'));
}; };
/** /**
@ -1454,7 +1459,7 @@ SQLConnector.prototype.getPlaceholderForValue = function(key) {
* @param {Object} filter The filter object from the query * @param {Object} filter The filter object from the query
*/ */
SQLConnector.prototype.applyPagination = function(model, stmt, filter) { SQLConnector.prototype.applyPagination = function(model, stmt, filter) {
throw new Error('applyPagination() must be implemented by the connector'); throw new Error(g.f('{{applyPagination()}} must be implemented by the connector'));
}; };
/** /**
@ -1465,7 +1470,8 @@ SQLConnector.prototype.applyPagination = function(model, stmt, filter) {
* @returns {Number} Number of rows affected * @returns {Number} Number of rows affected
*/ */
SQLConnector.prototype.getCountForAffectedRows = function(model, info) { SQLConnector.prototype.getCountForAffectedRows = function(model, info) {
throw new Error('getCountForAffectedRows() must be implemented by the connector'); throw new Error(g.f('{{getCountForAffectedRows()}} must be implemented by ' +
'the connector'));
}; };
/** /**
@ -1475,7 +1481,7 @@ SQLConnector.prototype.getCountForAffectedRows = function(model, info) {
* @returns {*} The inserted id value * @returns {*} The inserted id value
*/ */
SQLConnector.prototype.getInsertedId = function(model, info) { SQLConnector.prototype.getInsertedId = function(model, info) {
throw new Error('getInsertedId() must be implemented by the connector'); throw new Error(g.f('{{getInsertedId()}} must be implemented by the connector'));
}; };
/** /**
@ -1486,5 +1492,5 @@ SQLConnector.prototype.getInsertedId = function(model, info) {
* @param {Function} [callback] The callback function * @param {Function} [callback] The callback function
*/ */
SQLConnector.prototype.executeSQL = function(sql, params, options, callback) { SQLConnector.prototype.executeSQL = function(sql, params, options, callback) {
throw new Error('executeSQL() must be implemented by the connector'); throw new Error(g.f('{{executeSQL()}} must be implemented by the connector'));
}; };

View File

@ -20,7 +20,8 @@
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"async": "^1.0.0", "async": "^1.0.0",
"debug": "^2.2.0" "debug": "^2.2.0",
"strong-globalize": "^2.5.8"
}, },
"devDependencies": { "devDependencies": {
"chai": "~2.3.0", "chai": "~2.3.0",