0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-04-08 02:52:39 -05:00

Replaced i18n with tpl in core/server/api/v3 (#13548)

refs: #13380

- The i18n package is deprecated. It is being replaced with the tpl package.

Co-authored-by: Shadman Khan <shadmankhan@ShadmanMac.local>
This commit is contained in:
Shadman Ahmed Khan 2021-10-12 13:03:33 +05:30 committed by GitHub
parent 65d5b8d671
commit c1789a3a03
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 38 additions and 16 deletions

View file

@ -1,11 +1,15 @@
const api = require('./index');
const config = require('../../../shared/config');
const i18n = require('../../../shared/i18n');
const errors = require('@tryghost/errors');
const web = require('../../web');
const models = require('../../models');
const auth = require('../../services/auth');
const invitations = require('../../services/invitations');
const tpl = require('@tryghost/tpl');
const messages = {
notTheBlogOwner: 'You are not the site owner.'
};
module.exports = {
docName: 'authentication',
@ -50,7 +54,7 @@ module.exports = {
return models.User.findOne({role: 'Owner', status: 'all'})
.then((owner) => {
if (owner.id !== frame.options.context.user) {
throw new errors.NoPermissionError({message: i18n.t('errors.api.authentication.notTheBlogOwner')});
throw new errors.NoPermissionError({message: tpl(messages.notTheBlogOwner)});
}
});
},

View file

@ -1,8 +1,12 @@
const Promise = require('bluebird');
const i18n = require('../../../shared/i18n');
const errors = require('@tryghost/errors');
const models = require('../../models');
const ALLOWED_INCLUDES = ['count.posts'];
const tpl = require('@tryghost/tpl');
const messages = {
notFound: 'Author not found.'
};
module.exports = {
docName: 'authors',
@ -54,7 +58,7 @@ module.exports = {
.then((model) => {
if (!model) {
return Promise.reject(new errors.NotFoundError({
message: i18n.t('errors.api.authors.notFound')
message: tpl(messages.notFound)
}));
}

View file

@ -1,7 +1,12 @@
const models = require('../../models');
const i18n = require('../../../shared/i18n');
const errors = require('@tryghost/errors');
const megaService = require('../../services/mega');
const tpl = require('@tryghost/tpl');
const messages = {
emailNotFound: 'Email not found.',
retryNotAllowed: 'Only failed emails can be retried'
};
module.exports = {
docName: 'emails',
@ -24,7 +29,7 @@ module.exports = {
.then((model) => {
if (!model) {
throw new errors.NotFoundError({
message: i18n.t('errors.models.email.emailNotFound')
message: tpl(messages.emailNotFound)
});
}
@ -43,13 +48,13 @@ module.exports = {
.then(async (model) => {
if (!model) {
throw new errors.NotFoundError({
message: i18n.t('errors.models.email.emailNotFound')
message: tpl(messages.emailNotFound)
});
}
if (model.get('status') !== 'failed') {
throw new errors.IncorrectUsageError({
message: i18n.t('errors.models.email.retryNotAllowed')
message: tpl(messages.retryNotAllowed)
});
}

View file

@ -1,6 +1,6 @@
const i18n = require('../../../shared/i18n');
const errors = require('@tryghost/errors');
const models = require('../../models');
const tpl = require('@tryghost/tpl');
const getIntegrationsServiceInstance = require('../../services/integrations/integrations-service');
const integrationsService = getIntegrationsServiceInstance({
@ -8,6 +8,10 @@ const integrationsService = getIntegrationsServiceInstance({
ApiKeyModel: models.ApiKey
});
const messages = {
resourceNotFound: '{resource} not found.'
};
module.exports = {
docName: 'integrations',
browse: {
@ -51,7 +55,7 @@ module.exports = {
return models.Integration.findOne(data, Object.assign(options, {require: true}))
.catch(models.Integration.NotFoundError, () => {
throw new errors.NotFoundError({
message: i18n.t('errors.api.resource.resourceNotFound', {
message: tpl(messages.resourceNotFound, {
resource: 'Integration'
})
});
@ -136,7 +140,7 @@ module.exports = {
return models.Integration.destroy(Object.assign(options, {require: true}))
.catch(models.Integration.NotFoundError, () => {
return Promise.reject(new errors.NotFoundError({
message: i18n.t('errors.api.resource.resourceNotFound', {
message: tpl(messages.resourceNotFound, {
resource: 'Integration'
})
}));

View file

@ -1,7 +1,12 @@
const Promise = require('bluebird');
const i18n = require('../../../shared/i18n');
const errors = require('@tryghost/errors');
const models = require('../../models');
const tpl = require('@tryghost/tpl');
const messages = {
labelNotFound: 'Label not found.',
labelAlreadyExists: 'Label already exists'
};
const ALLOWED_INCLUDES = ['count.members'];
@ -53,7 +58,7 @@ module.exports = {
.then((model) => {
if (!model) {
return Promise.reject(new errors.NotFoundError({
message: i18n.t('errors.api.labels.labelNotFound')
message: tpl(messages.labelNotFound)
}));
}
@ -80,7 +85,7 @@ module.exports = {
return models.Label.add(frame.data.labels[0], frame.options)
.catch((error) => {
if (error.code && error.message.toLowerCase().indexOf('unique') !== -1) {
throw new errors.ValidationError({message: i18n.t('errors.api.labels.labelAlreadyExists')});
throw new errors.ValidationError({message: tpl(messages.labelAlreadyExists)});
}
throw error;
@ -110,7 +115,7 @@ module.exports = {
.then((model) => {
if (!model) {
return Promise.reject(new errors.NotFoundError({
message: i18n.t('errors.api.labels.labelNotFound')
message: tpl(messages.labelNotFound)
}));
}
@ -149,7 +154,7 @@ module.exports = {
.then(() => null)
.catch(models.Label.NotFoundError, () => {
return Promise.reject(new errors.NotFoundError({
message: i18n.t('errors.api.labels.labelNotFound')
message: tpl(messages.labelNotFound)
}));
});
}