mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-27 22:49:56 -05:00
Replaced i18n.t w/ tpl helper in members.js (#13456)
refs: #13380 - The i18n package is deprecated. It is being replaced with the tpl package.
This commit is contained in:
parent
ff0b1a61b3
commit
c06c63b92b
1 changed files with 32 additions and 14 deletions
|
@ -8,9 +8,27 @@ const membersService = require('../../services/members');
|
||||||
const labsService = require('../../../shared/labs');
|
const labsService = require('../../../shared/labs');
|
||||||
|
|
||||||
const settingsCache = require('../../../shared/settings-cache');
|
const settingsCache = require('../../../shared/settings-cache');
|
||||||
const i18n = require('../../../shared/i18n');
|
const tpl = require('@tryghost/tpl');
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
|
|
||||||
|
const messages = {
|
||||||
|
memberNotFound: 'Member not found.',
|
||||||
|
memberAlreadyExists: {
|
||||||
|
message: 'Member already exists',
|
||||||
|
context: 'Attempting to {action} member with existing email address.'
|
||||||
|
},
|
||||||
|
stripeNotConnected: {
|
||||||
|
message: 'Missing Stripe connection.',
|
||||||
|
context: 'Attempting to import members with Stripe data when there is no Stripe account connected.',
|
||||||
|
help: 'help'
|
||||||
|
},
|
||||||
|
stripeCustomerNotFound: {
|
||||||
|
context: 'Missing Stripe customer.',
|
||||||
|
help: 'Make sure you’re connected to the correct Stripe Account.'
|
||||||
|
},
|
||||||
|
resourceNotFound: '{resource} not found.'
|
||||||
|
};
|
||||||
|
|
||||||
const allowedIncludes = ['email_recipients', 'products'];
|
const allowedIncludes = ['email_recipients', 'products'];
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
@ -70,7 +88,7 @@ module.exports = {
|
||||||
|
|
||||||
if (!member) {
|
if (!member) {
|
||||||
throw new errors.NotFoundError({
|
throw new errors.NotFoundError({
|
||||||
message: i18n.t('errors.api.members.memberNotFound')
|
message: tpl(messages.memberNotFound)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,9 +126,9 @@ module.exports = {
|
||||||
const property = frame.data.members[0].comped ? 'comped' : 'stripe_customer_id';
|
const property = frame.data.members[0].comped ? 'comped' : 'stripe_customer_id';
|
||||||
|
|
||||||
throw new errors.ValidationError({
|
throw new errors.ValidationError({
|
||||||
message: i18n.t('errors.api.members.stripeNotConnected.message'),
|
message: tpl(messages.stripeNotConnected.message),
|
||||||
context: i18n.t('errors.api.members.stripeNotConnected.context'),
|
context: tpl(messages.stripeNotConnected.context),
|
||||||
help: i18n.t('errors.api.members.stripeNotConnected.help'),
|
help: tpl(messages.stripeNotConnected.help),
|
||||||
property
|
property
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -138,8 +156,8 @@ module.exports = {
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error.code && error.message.toLowerCase().indexOf('unique') !== -1) {
|
if (error.code && error.message.toLowerCase().indexOf('unique') !== -1) {
|
||||||
throw new errors.ValidationError({
|
throw new errors.ValidationError({
|
||||||
message: i18n.t('errors.models.member.memberAlreadyExists.message'),
|
message: tpl(messages.memberAlreadyExists.message),
|
||||||
context: i18n.t('errors.models.member.memberAlreadyExists.context', {
|
context: tpl(messages.memberAlreadyExists.context, {
|
||||||
action: 'add'
|
action: 'add'
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
@ -152,8 +170,8 @@ module.exports = {
|
||||||
if (member && isStripeLinkingError) {
|
if (member && isStripeLinkingError) {
|
||||||
if (error.message.indexOf('customer') && error.code === 'resource_missing') {
|
if (error.message.indexOf('customer') && error.code === 'resource_missing') {
|
||||||
error.message = `Member not imported. ${error.message}`;
|
error.message = `Member not imported. ${error.message}`;
|
||||||
error.context = i18n.t('errors.api.members.stripeCustomerNotFound.context');
|
error.context = tpl(messages.stripeCustomerNotFound.context);
|
||||||
error.help = i18n.t('errors.api.members.stripeCustomerNotFound.help');
|
error.help = tpl(messages.stripeCustomerNotFound.help);
|
||||||
}
|
}
|
||||||
|
|
||||||
await membersService.api.members.destroy({
|
await membersService.api.members.destroy({
|
||||||
|
@ -208,8 +226,8 @@ module.exports = {
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error.code && error.message.toLowerCase().indexOf('unique') !== -1) {
|
if (error.code && error.message.toLowerCase().indexOf('unique') !== -1) {
|
||||||
throw new errors.ValidationError({
|
throw new errors.ValidationError({
|
||||||
message: i18n.t('errors.models.member.memberAlreadyExists.message'),
|
message: tpl(messages.memberAlreadyExists.message),
|
||||||
context: i18n.t('errors.models.member.memberAlreadyExists.context', {
|
context: tpl(messages.memberAlreadyExists.context, {
|
||||||
action: 'edit'
|
action: 'edit'
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
@ -274,7 +292,7 @@ module.exports = {
|
||||||
});
|
});
|
||||||
if (!model) {
|
if (!model) {
|
||||||
throw new errors.NotFoundError({
|
throw new errors.NotFoundError({
|
||||||
message: i18n.t('errors.api.members.memberNotFound')
|
message: tpl(messages.memberNotFound)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -318,7 +336,7 @@ module.exports = {
|
||||||
});
|
});
|
||||||
if (!model) {
|
if (!model) {
|
||||||
throw new errors.NotFoundError({
|
throw new errors.NotFoundError({
|
||||||
message: i18n.t('errors.api.members.memberNotFound')
|
message: tpl(messages.memberNotFound)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -349,7 +367,7 @@ module.exports = {
|
||||||
id: frame.options.id
|
id: frame.options.id
|
||||||
}, frame.options)).catch(models.Member.NotFoundError, () => {
|
}, frame.options)).catch(models.Member.NotFoundError, () => {
|
||||||
throw new errors.NotFoundError({
|
throw new errors.NotFoundError({
|
||||||
message: i18n.t('errors.api.resource.resourceNotFound', {
|
message: tpl(messages.resourceNotFound, {
|
||||||
resource: 'Member'
|
resource: 'Member'
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue