Remove i18n dependency from notifications service

refs https://github.com/TryGhost/Ghost/issues/13380

- The i18n package is deprecated. It is being replaced with the tpl package.
This commit is contained in:
Naz 2021-10-07 17:36:13 +02:00
parent f8dd0b3d56
commit 84118068c8
2 changed files with 9 additions and 7 deletions

View File

@ -1,12 +1,10 @@
const settingsCache = require('../../../shared/settings-cache');
const i18n = require('../../../shared/i18n');
const ghostVersion = require('@tryghost/version');
const Notifications = require('./notifications');
const models = require('../../models');
module.exports.notifications = new Notifications({
settingsCache,
i18n,
ghostVersion,
SettingsModel: models.Settings
});

View File

@ -3,21 +3,25 @@ const semver = require('semver');
const Promise = require('bluebird');
const _ = require('lodash');
const errors = require('@tryghost/errors');
const tpl = require('@tryghost/tpl');
const ObjectId = require('bson-objectid');
const messages = {
noPermissionToDismissNotif: 'You do not have permission to dismiss this notification.',
notificationDoesNotExist: 'Notification does not exist.'
};
class Notifications {
/**
*
* @param {Object} options
* @param {Object} options.settingsCache - settings cache instance
* @param {Object} options.i18n - i18n instance
* @param {Object} options.ghostVersion
* @param {String} options.ghostVersion.full - Ghost instance version in "full" format - major.minor.patch
* @param {Object} options.SettingsModel - Ghost's Setting model instance
*/
constructor({settingsCache, i18n, ghostVersion, SettingsModel}) {
constructor({settingsCache, ghostVersion, SettingsModel}) {
this.settingsCache = settingsCache;
this.i18n = i18n;
this.ghostVersion = ghostVersion;
this.SettingsModel = SettingsModel;
}
@ -195,13 +199,13 @@ class Notifications {
if (notificationToMarkAsSeenIndex > -1 && !notificationToMarkAsSeen.dismissible) {
return Promise.reject(new errors.NoPermissionError({
message: this.i18n.t('errors.api.notifications.noPermissionToDismissNotif')
message: tpl(messages.noPermissionToDismissNotif)
}));
}
if (notificationToMarkAsSeenIndex < 0) {
return Promise.reject(new errors.NotFoundError({
message: this.i18n.t('errors.api.notifications.notificationDoesNotExist')
message: tpl(messages.notificationDoesNotExist)
}));
}