-
Notifications
You must be signed in to change notification settings - Fork 94
Add globalization #118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add globalization #118
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,3 +22,7 @@ xunit.xml | |
| checkstyle.xml | ||
| example/server-2.0/client/public/vendor | ||
| doc | ||
|
|
||
| !intl/ | ||
| intl/* | ||
| !intl/en/ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| { | ||
| "0a11bfdd7655e825fbd1f998b2e24db9": "Empty payload", | ||
| "71a2b601d1e750aa05c7a28ed76b9973": "Invalid field (empty)", | ||
| "8bc87eb582af546d32505f2839234119": "Invalid payload", | ||
| "db1e3eb9bf0934d72eb8b0b110281f39": "Invalid field: {0}", | ||
| "e254b20a16461c7379202f6a5f8350cc": "Invalid variable type for ${{0}}", | ||
| "f5146dece5cd70db519daf8c7e6d8478": "The ${{0}} does not exist", | ||
| "f95c75ae3da1e88794fff4be7188f3dc": "Invalid value for `{0}`", | ||
| "e9023b2ab0a052c9ccbd257198c7429f": "Cannot send {{APNS}} notification: {0}", | ||
| "704e7bf9910b8532f7c4889366fdcbac": "{{GCM}} error code: {0}, deviceToken: {1}", | ||
| "033d31e7bd62a420f23e4b154945a2b8": "notification must be an object", | ||
| "1ec12f42dab8979b9fc90a95a023419e": "deviceTokens must be an array" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,8 @@ | |
| // this file has no tests so avoid refactor and ignore jshint for now | ||
| /*jshint ignore: start */ | ||
| var serial,__hasProp = {}.hasOwnProperty; | ||
| var SG = require('strong-globalize'); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not following strong-globalize coding guideline here? |
||
| var g = SG(); | ||
|
|
||
| serial = 0; | ||
|
|
||
|
|
@@ -14,7 +16,7 @@ Payload.prototype.locale_format = /^[a-z]{2}_[A-Z]{2}$/; | |
| function Payload(data) { | ||
| var key, prefix, subkey, sum, type, value, _i, _len, _ref, _ref1; | ||
| if (typeof data !== 'object') { | ||
| throw new Error('Invalid payload'); | ||
| throw new Error(g.t('Invalid payload')); | ||
| } | ||
| this.id = serial++; | ||
| this.compiled = false; | ||
|
|
@@ -26,11 +28,12 @@ function Payload(data) { | |
| if (!__hasProp.call(data, key)) continue; | ||
| value = data[key]; | ||
| if (typeof key !== 'string' || key.length === 0) { | ||
| throw new Error("Invalid field (empty)"); | ||
| throw new Error(g.t("Invalid field (empty)")); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nitpick: change it to
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That would make it an unrelated change. That should be done in a separate PR (ie. Change double quotes to single quotes). |
||
| } | ||
| if (typeof value !== 'string') { | ||
| throw new Error("Invalid value for `" + key + "'"); | ||
| throw new Error(g.f("Invalid value for `%s`", key)); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
| } | ||
|
|
||
| switch (key) { | ||
| case 'title': | ||
| this.title["default"] = value; | ||
|
|
@@ -45,7 +48,7 @@ function Payload(data) { | |
| if ((_ref = key.split('.', 2), prefix = _ref[0], subkey = _ref[1], _ref).length === 2) { | ||
| this[prefix][subkey] = value; | ||
| } else { | ||
| throw new Error("Invalid field: " + key); | ||
| throw new Error(g.f("Invalid field: %s", key)); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same |
||
| } | ||
| } | ||
| } | ||
|
|
@@ -65,7 +68,7 @@ function Payload(data) { | |
| }).call(this)).length; | ||
| } | ||
| if (sum === 0) { | ||
| throw new Error('Empty payload'); | ||
| throw new Error(g.t('Empty payload')); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -118,15 +121,15 @@ Payload.prototype.variable = function (keyPath) { | |
| if ((_ref = this.event) != null ? _ref.name : undefined) { | ||
| return (_ref1 = this.event) != null ? _ref1.name : undefined; | ||
| } else { | ||
| throw new Error("The ${" + keyPath + "} does not exist"); | ||
| throw new Error(g.f("The ${%s} does not exist", keyPath)); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same |
||
| } | ||
| } | ||
| _ref2 = keyPath.split('.', 2), prefix = _ref2[0], key = _ref2[1]; | ||
| if (prefix !== 'var' && prefix !== 'data') { | ||
| throw new Error("Invalid variable type for ${" + keyPath + "}"); | ||
| throw new Error(g.f("Invalid variable type for ${%s}", keyPath)); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same |
||
| } | ||
| if (this[prefix][key] == null) { | ||
| throw new Error("The ${" + keyPath + "} does not exist"); | ||
| throw new Error(g.f("The ${%s} does not exist", keyPath)); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same |
||
| } | ||
| return this[prefix][key]; | ||
| }; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,9 +5,10 @@ | |
|
|
||
| var inherits = require('util').inherits; | ||
| var EventEmitter = require('events').EventEmitter; | ||
|
|
||
| var debug = require('debug')('loopback:component:push:provider:apns'); | ||
| var apn = require('apn'); | ||
| var SG = require('strong-globalize'); | ||
| var g = SG(); | ||
|
|
||
| function ApnsProvider(pushSettings) { | ||
| pushSettings = pushSettings || {}; | ||
|
|
@@ -83,7 +84,7 @@ ApnsProvider.prototype._setupPushConnection = function(options) { | |
| connection.on('socketError', errorHandler); | ||
|
|
||
| connection.on('transmissionError', function(code, notification, recipient) { | ||
| var err = new Error('Cannot send APNS notification: ' + code); | ||
| var err = new Error(g.f('Cannot send {{APNS}} notification: %s', code)); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You have to run |
||
| self.emit(err, notification, recipient); | ||
| }); | ||
|
|
||
|
|
@@ -140,4 +141,4 @@ ApnsProvider.prototype.pushNotification = function(notification, deviceToken) { | |
|
|
||
| debug('Pushing notification to %j:', deviceToken, note); | ||
| this._connection.pushNotification(note, deviceToken); | ||
| }; | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,8 @@ var extend = require('util')._extend; | |
| var EventEmitter = require('events').EventEmitter; | ||
| var gcm = require('node-gcm'); | ||
| var debug = require('debug')('loopback:component:push:provider:gcm'); | ||
| var SG = require('strong-globalize'); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not following strong-globalize coding guideline here? |
||
| var g = SG(); | ||
|
|
||
| function GcmProvider(pushSettings) { | ||
| var settings = pushSettings.gcm || {}; | ||
|
|
@@ -39,7 +41,8 @@ GcmProvider.prototype.pushNotification = function(notification, deviceToken) { | |
| debug('Device %j is no longer registered.', registrationIds[index]); | ||
| devicesGoneRegistrationIds.push(registrationIds[index]); | ||
| } else if (code) { | ||
| errors.push('GCM error code: ' + (code || 'Unknown') + ', deviceToken: ' + registrationIds[index]); | ||
| errors.push(g.f('{{GCM}} error code: %s, deviceToken: %s', | ||
| (code || 'Unknown'), registrationIds[index])); | ||
| } | ||
| }); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,8 @@ var providers = require('./providers'); | |
| var loopback = require('loopback'); | ||
| var NodeCache = require('node-cache'); | ||
| var debug = require('debug')('loopback:component:push:push-manager'); | ||
| var SG = require('strong-globalize'); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not following strong-globalize coding guideline here? |
||
| var g = SG(); | ||
|
|
||
| var Installation = require('../models').Installation; | ||
| var Notification = require('../models').Notification; | ||
|
|
@@ -277,7 +279,7 @@ PushManager.prototype.notify = function(installation, notification, cb) { | |
| assert(cb, 'callback should be defined'); | ||
|
|
||
| if(!(typeof notification === 'object' && notification)) { | ||
| return cb(new Error('notification must be an object')); | ||
| return cb(new Error(g.t('notification must be an object'))); | ||
| } | ||
|
|
||
| var appId = installation.appId; | ||
|
|
@@ -327,11 +329,11 @@ PushManager.prototype.notifyMany = function(appId, deviceType, deviceTokens, not | |
| assert(cb, 'callback should be defined'); | ||
|
|
||
| if(!(typeof notification === 'object' && notification)) { | ||
| return cb(new Error('notification must be an object')); | ||
| return cb(new Error(g.t('notification must be an object'))); | ||
| } | ||
|
|
||
| if(!(Array.isArray(deviceTokens) && deviceTokens.length > 0)) { | ||
| return cb(new Error('deviceTokens must be an array')); | ||
| return cb(new Error(g.t('deviceTokens must be an array'))); | ||
| } | ||
|
|
||
| // Normalize the notification from a plain object | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not following strong-globalize coding guideline here?
https://www.npmjs.com/package/strong-globalize#autonomous-message-loading
Please study paragraphs after "For example, the following does not work as intended because the package sub calls SG.SetRootDir first:"