Skip to content

Commit dcf5d8c

Browse files
author
Janny
authored
Merge pull request loopbackio#152 from strongloop/globalization
Globalize postgresql
2 parents 261877c + aa63800 commit dcf5d8c

File tree

8 files changed

+35
-8
lines changed

8 files changed

+35
-8
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,7 @@ results
1717

1818
npm-debug.log
1919
docs
20+
21+
!intl/
22+
intl/*
23+
!intl/en/

example/model.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Node module: loopback-connector-postgresql
33
// This file is licensed under the Artistic License 2.0.
44
// License text available at https://opensource.org/licenses/Artistic-2.0
5+
var SG = require('strong-globalize');
6+
var g = SG();
57

68
var DataSource = require('loopback-datasource-juggler').DataSource;
79

index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,7 @@
33
// This file is licensed under the Artistic License 2.0.
44
// License text available at https://opensource.org/licenses/Artistic-2.0
55

6+
var SG = require('strong-globalize');
7+
SG.SetRootDir(__dirname);
8+
69
module.exports = require('./lib/postgresql.js');

intl/en/messages.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"a0078d732b2dbabf98ed2efcdb55b402": "{{table}} is a required string argument: {0}",
3+
"fc3b8fde2e08c74cafb55f25c4841a4b": "{{options}} must be an object: {0}",
4+
"16cbc6b164ad51e193938132d059ce3f": "{{Index keys}} definition appears to be invalid: {0}",
5+
"80a32e80cbed65eba2103201a7c94710": "Model not found: {0}",
6+
"1752695ee513f17d70e82753c0b6ef1a": "{{PostgreSQL}} regex syntax does not respect the {{`m`}} flag",
7+
"b811d24a7d249e0aedff11523626fbfd": "{{Placeholder}} for identifiers is not supported",
8+
"bfe8fb104f017b365e64da57ed975db6": "{{PostgreSQL}} regex syntax does not respect the {{`g`}} flag"
9+
}

lib/discovery.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
// This file is licensed under the Artistic License 2.0.
44
// License text available at https://opensource.org/licenses/Artistic-2.0
55

6+
var SG = require('strong-globalize');
7+
var g = SG();
8+
69
module.exports = mixinDiscovery;
710

811
function mixinDiscovery(PostgreSQL) {
@@ -119,15 +122,15 @@ function mixinDiscovery(PostgreSQL) {
119122
*/
120123
function getArgs(table, options, cb) {
121124
if ('string' !== typeof table || !table) {
122-
throw new Error('table is a required string argument: ' + table);
125+
throw new Error(g.f('{{table}} is a required string argument: %s' + table));
123126
}
124127
options = options || {};
125128
if (!cb && 'function' === typeof options) {
126129
cb = options;
127130
options = {};
128131
}
129132
if (typeof options !== 'object') {
130-
throw new Error('options must be an object: ' + options);
133+
throw new Error(g.f('{{options}} must be an object: %s' + options));
131134
}
132135
return {
133136
owner: options.owner || options.schema,

lib/migration.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
// This file is licensed under the Artistic License 2.0.
44
// License text available at https://opensource.org/licenses/Artistic-2.0
55

6+
var SG = require('strong-globalize');
7+
var g = SG();
68
var async = require('async');
9+
710
module.exports = mixinMigration;
811

912
function mixinMigration(PostgreSQL) {
@@ -92,7 +95,7 @@ function mixinMigration(PostgreSQL) {
9295
async.each(models, function(model, done) {
9396
if (!(model in self._models)) {
9497
return process.nextTick(function() {
95-
done(new Error('Model not found: ' + model));
98+
done(new Error(g.f('Model not found: %s' + model)));
9699
});
97100
}
98101
self.getTableStatus(model, function(err, fields, indexes) {
@@ -821,7 +824,7 @@ function mixinMigration(PostgreSQL) {
821824
return column && [column, 'ASC'];
822825
});
823826
} else {
824-
throw Error('Index keys definition appears to be invalid: ', keys);
827+
throw Error(g.f('{{Index keys}} definition appears to be invalid: %s', keys));
825828
}
826829

827830
return result;

lib/postgresql.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
/*!
77
* PostgreSQL connector for LoopBack
88
*/
9+
var SG = require('strong-globalize');
10+
var g = SG();
911
var postgresql = require('pg');
1012
var SqlConnector = require('loopback-connector').SqlConnector;
1113
var ParameterizedSQL = SqlConnector.ParameterizedSQL;
@@ -385,10 +387,10 @@ PostgreSQL.prototype.buildExpression = function(columnName, operator,
385387
[operatorValue]);
386388
case 'regexp':
387389
if (operatorValue.global)
388-
console.warn('PostgreSQL regex syntax does not respect the `g` flag');
390+
g.warn('{{PostgreSQL}} regex syntax does not respect the {{`g`}} flag');
389391

390392
if (operatorValue.multiline)
391-
console.warn('PostgreSQL regex syntax does not respect the `m` flag');
393+
g.warn('{{PostgreSQL}} regex syntax does not respect the {{`m`}} flag');
392394

393395
var regexOperator = operatorValue.ignoreCase ? ' ~* ?' : ' ~ ?';
394396
return new ParameterizedSQL(columnName + regexOperator,
@@ -499,7 +501,7 @@ PostgreSQL.prototype.toColumnValue = function(prop, val) {
499501
* @returns {String} The place holder
500502
*/
501503
PostgreSQL.prototype.getPlaceholderForIdentifier = function(key) {
502-
throw new Error('Placeholder for identifiers is not supported');
504+
throw new Error(g.f('{{Placeholder}} for identifiers is not supported'));
503505
};
504506

505507
/**

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
"async": "^0.9.0",
1818
"debug": "^2.1.1",
1919
"loopback-connector": "^2.1.0",
20-
"pg": "^6.0.0"
20+
"pg": "^6.0.0",
21+
"strong-globalize": "^2.5.8"
2122
},
2223
"devDependencies": {
2324
"bluebird": "^2.9.12",

0 commit comments

Comments
 (0)