From bf4c5c861d38eab0300a6e6a290b4168c5c8bff9 Mon Sep 17 00:00:00 2001 From: Bruno Silva Date: Tue, 5 Oct 2021 06:36:12 -0300 Subject: [PATCH] Replace i18n with tpl in some files under core/server/api/v2 (#13445) refs: #13380 - The i18n package is deprecated. It is being replaced with the tpl package. Replace the deprecated dependency `i18n` with `tpl` in the following files under `core/server/api/v2/`: - authors-public.js - pages-public.js - session.js --- core/server/api/v2/authors-public.js | 8 ++++++-- core/server/api/v2/pages-public.js | 8 ++++++-- core/server/api/v2/session.js | 10 +++++++--- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/core/server/api/v2/authors-public.js b/core/server/api/v2/authors-public.js index 90726c0c10..a78775343a 100644 --- a/core/server/api/v2/authors-public.js +++ b/core/server/api/v2/authors-public.js @@ -1,9 +1,13 @@ const Promise = require('bluebird'); -const i18n = require('../../../shared/i18n'); +const tpl = require('@tryghost/tpl'); const errors = require('@tryghost/errors'); const models = require('../../models'); const ALLOWED_INCLUDES = ['count.posts']; +const messages = { + authorsNotFound: '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.authorsNotFound) })); } diff --git a/core/server/api/v2/pages-public.js b/core/server/api/v2/pages-public.js index dcb46dacc9..40d809d9b2 100644 --- a/core/server/api/v2/pages-public.js +++ b/core/server/api/v2/pages-public.js @@ -1,8 +1,12 @@ -const i18n = require('../../../shared/i18n'); +const tpl = require('@tryghost/tpl'); const errors = require('@tryghost/errors'); const models = require('../../models'); const ALLOWED_INCLUDES = ['tags', 'authors']; +const messages = { + pageNotFound: 'Page not found' +}; + module.exports = { docName: 'pages', @@ -63,7 +67,7 @@ module.exports = { .then((model) => { if (!model) { throw new errors.NotFoundError({ - message: i18n.t('errors.api.pages.pageNotFound') + message: tpl(messages.pageNotFound) }); } diff --git a/core/server/api/v2/session.js b/core/server/api/v2/session.js index a6c82011eb..9687a71921 100644 --- a/core/server/api/v2/session.js +++ b/core/server/api/v2/session.js @@ -1,10 +1,14 @@ const Promise = require('bluebird'); -const i18n = require('../../../shared/i18n'); +const tpl = require('@tryghost/tpl'); const errors = require('@tryghost/errors'); const models = require('../../models'); const auth = require('../../services/auth'); const api = require('./index'); +const messages = { + authAccessDenied: 'Access denied.' +}; + const session = { read(frame) { /* @@ -20,7 +24,7 @@ const session = { if (!object || !object.username || !object.password) { return Promise.reject(new errors.UnauthorizedError({ - message: i18n.t('errors.middleware.auth.accessDenied') + message: tpl(messages.authAccessDenied) })); } @@ -40,7 +44,7 @@ const session = { }).catch(async (err) => { if (!errors.utils.isIgnitionError(err)) { throw new errors.UnauthorizedError({ - message: i18n.t('errors.middleware.auth.accessDenied'), + message: tpl(messages.authAccessDenied), err }); }