Merge pull request #178 from strongloop/initial_glob

Add globalization
This commit is contained in:
Candy 2016-08-04 11:16:46 -04:00 committed by GitHub
commit 0fcaa35f52
8 changed files with 32 additions and 9 deletions

2
.gitignore vendored
View File

@ -4,3 +4,5 @@ coverage
*.xml *.xml
.loopbackrc .loopbackrc
.idea .idea
intl/*
!intl/en/

View File

@ -3,4 +3,7 @@
// 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);
module.exports = require('./lib/mysql.js'); module.exports = require('./lib/mysql.js');

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

@ -0,0 +1,10 @@
{
"6ce5c3a3d305e965ff06e2b3e16e1252": "{{options}} must be an {{object}}: {0}",
"a0078d732b2dbabf98ed2efcdb55b402": "{{table}} is a required string argument: {0}",
"b7c60421de706ca1e050f2a86953745e": "No arguments - could not create {{Enum}}.",
"80a32e80cbed65eba2103201a7c94710": "Model not found: {0}",
"026ed55518f3812a9ef4b86e8a195e76": "{{MySQL}} {{regex}} syntax does not respect the {{`g`}} flag",
"0ac9f848b934332210bb27747d12a033": "{{MySQL}} {{regex}} syntax does not respect the {{`i`}} flag",
"4e9e35876bfb1511205456b52c6659d0": "{{MySQL}} {{regex}} syntax does not respect the {{`m`}} flag",
"57512a471969647e8eaa2509cc292018": "{{callback}} should be a function"
}

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 g = require('strong-globalize')();
module.exports = mixinDiscovery; module.exports = mixinDiscovery;
/*! /*!
@ -167,7 +169,7 @@ function mixinDiscovery(MySQL, mysql) {
*/ */
function getArgs(table, options, cb) { function getArgs(table, options, cb) {
if ('string' !== typeof table || !table) { if ('string' !== typeof table || !table) {
throw new Error('table is a required string argument: ' + table); throw new Error(g.f('{{table}} is a required string argument: %s', table));
} }
options = options || {}; options = options || {};
if (!cb && 'function' === typeof options) { if (!cb && 'function' === typeof options) {
@ -175,7 +177,7 @@ function mixinDiscovery(MySQL, mysql) {
options = {}; options = {};
} }
if (typeof options !== 'object') { if (typeof options !== 'object') {
throw new Error('options must be an object: ' + options); throw new Error(g.f('{{options}} must be an {{object}}: %s', options));
} }
return { return {
schema: options.owner || options.schema, schema: options.owner || options.schema,

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 g = require('strong-globalize')();
var EnumFactory = function() { var EnumFactory = function() {
if (arguments.length > 0) { if (arguments.length > 0) {
var Enum = function Enum(arg) { var Enum = function Enum(arg) {
@ -47,7 +49,7 @@ var EnumFactory = function() {
Object.freeze(Enum); Object.freeze(Enum);
return Enum; return Enum;
} else { } else {
throw "No arguments - could not create Enum."; throw g.f("No arguments - could not create {{Enum}}.");
} }
}; };

View File

@ -3,6 +3,7 @@
// 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 g = require('strong-globalize')();
var async = require('async'); var async = require('async');
module.exports = mixinMigration; module.exports = mixinMigration;
@ -34,7 +35,7 @@ function mixinMigration(MySQL, mysql) {
async.each(models, function(model, done) { async.each(models, function(model, done) {
if (!(model in self._models)) { if (!(model in self._models)) {
return process.nextTick(function() { return process.nextTick(function() {
done(new Error('Model not found: ' + model)); done(new Error(g.f('Model not found: %s', model)));
}); });
} }
var table = self.tableEscaped(model); var table = self.tableEscaped(model);

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 g = require('strong-globalize')();
/*! /*!
* Module dependencies * Module dependencies
*/ */
@ -164,7 +166,7 @@ MySQL.prototype.executeSQL = function(sql, params, options, callback) {
var debugEnabled = debug.enabled; var debugEnabled = debug.enabled;
var db = this.settings.database; var db = this.settings.database;
if (typeof callback !== 'function') { if (typeof callback !== 'function') {
throw new Error('callback should be a function'); throw new Error(g.f('{{callback}} should be a function'));
} }
if (debugEnabled) { if (debugEnabled) {
debug('SQL: %s, params: %j', sql, params); debug('SQL: %s, params: %j', sql, params);
@ -517,13 +519,13 @@ MySQL.prototype.buildExpression = function(columnName, operator, operatorValue,
propertyDefinition) { propertyDefinition) {
if (operator === 'regexp') { if (operator === 'regexp') {
if (operatorValue.ignoreCase) if (operatorValue.ignoreCase)
console.warn('MySQL regex syntax does not respect the `i` flag'); g.warn('{{MySQL}} {{regex}} syntax does not respect the {{`i`}} flag');
if (operatorValue.global) if (operatorValue.global)
console.warn('MySQL regex syntax does not respect the `g` flag'); g.warn('{{MySQL}} {{regex}} syntax does not respect the {{`g`}} flag');
if (operatorValue.multiline) if (operatorValue.multiline)
console.warn('MySQL regex syntax does not respect the `m` flag'); g.warn('{{MySQL}} {{regex}} syntax does not respect the {{`m`}} flag');
return new ParameterizedSQL(columnName + ' REGEXP ?', return new ParameterizedSQL(columnName + ' REGEXP ?',
[operatorValue.source]); [operatorValue.source]);

View File

@ -10,7 +10,8 @@
"async": "^0.9.0", "async": "^0.9.0",
"debug": "^2.1.1", "debug": "^2.1.1",
"loopback-connector": "^2.1.0", "loopback-connector": "^2.1.0",
"mysql": "^2.5.4" "mysql": "^2.5.4",
"strong-globalize": "^2.5.8"
}, },
"devDependencies": { "devDependencies": {
"bluebird": "~2.9.10", "bluebird": "~2.9.10",