diff --git a/.gitignore b/.gitignore index 5b2da1d..f9b53a5 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ coverage *.xml .loopbackrc .idea +intl/* +!intl/en/ \ No newline at end of file diff --git a/index.js b/index.js index b66031d..f9ff8d8 100644 --- a/index.js +++ b/index.js @@ -3,4 +3,7 @@ // This file is licensed under the MIT License. // License text available at https://opensource.org/licenses/MIT +var SG = require('strong-globalize'); +SG.SetRootDir(__dirname); + module.exports = require('./lib/mysql.js'); diff --git a/intl/en/messages.json b/intl/en/messages.json new file mode 100644 index 0000000..7e4acdf --- /dev/null +++ b/intl/en/messages.json @@ -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" +} diff --git a/lib/discovery.js b/lib/discovery.js index 8fb593b..6a6a731 100644 --- a/lib/discovery.js +++ b/lib/discovery.js @@ -3,6 +3,8 @@ // This file is licensed under the MIT License. // License text available at https://opensource.org/licenses/MIT +var g = require('strong-globalize')(); + module.exports = mixinDiscovery; /*! @@ -167,7 +169,7 @@ function mixinDiscovery(MySQL, mysql) { */ function getArgs(table, options, cb) { 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 || {}; if (!cb && 'function' === typeof options) { @@ -175,7 +177,7 @@ function mixinDiscovery(MySQL, mysql) { options = {}; } 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 { schema: options.owner || options.schema, diff --git a/lib/enumFactory.js b/lib/enumFactory.js index c4edd0e..12844f8 100644 --- a/lib/enumFactory.js +++ b/lib/enumFactory.js @@ -3,6 +3,8 @@ // This file is licensed under the MIT License. // License text available at https://opensource.org/licenses/MIT +var g = require('strong-globalize')(); + var EnumFactory = function() { if (arguments.length > 0) { var Enum = function Enum(arg) { @@ -47,7 +49,7 @@ var EnumFactory = function() { Object.freeze(Enum); return Enum; } else { - throw "No arguments - could not create Enum."; + throw g.f("No arguments - could not create {{Enum}}."); } }; diff --git a/lib/migration.js b/lib/migration.js index 7f7fe13..143c912 100644 --- a/lib/migration.js +++ b/lib/migration.js @@ -3,6 +3,7 @@ // This file is licensed under the MIT License. // License text available at https://opensource.org/licenses/MIT +var g = require('strong-globalize')(); var async = require('async'); module.exports = mixinMigration; @@ -34,7 +35,7 @@ function mixinMigration(MySQL, mysql) { async.each(models, function(model, done) { if (!(model in self._models)) { 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); diff --git a/lib/mysql.js b/lib/mysql.js index 7527ff6..215e1dc 100644 --- a/lib/mysql.js +++ b/lib/mysql.js @@ -3,6 +3,8 @@ // This file is licensed under the MIT License. // License text available at https://opensource.org/licenses/MIT +var g = require('strong-globalize')(); + /*! * Module dependencies */ @@ -164,7 +166,7 @@ MySQL.prototype.executeSQL = function(sql, params, options, callback) { var debugEnabled = debug.enabled; var db = this.settings.database; if (typeof callback !== 'function') { - throw new Error('callback should be a function'); + throw new Error(g.f('{{callback}} should be a function')); } if (debugEnabled) { debug('SQL: %s, params: %j', sql, params); @@ -517,13 +519,13 @@ MySQL.prototype.buildExpression = function(columnName, operator, operatorValue, propertyDefinition) { if (operator === 'regexp') { 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) - 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) - 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 ?', [operatorValue.source]); diff --git a/package.json b/package.json index b4374d2..96a91a6 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,8 @@ "async": "^0.9.0", "debug": "^2.1.1", "loopback-connector": "^2.1.0", - "mysql": "^2.5.4" + "mysql": "^2.5.4", + "strong-globalize": "^2.5.8" }, "devDependencies": { "bluebird": "~2.9.10",