diff --git a/core/frontend/apps/amp/lib/router.js b/core/frontend/apps/amp/lib/router.js index 870530417f..4403662f1a 100644 --- a/core/frontend/apps/amp/lib/router.js +++ b/core/frontend/apps/amp/lib/router.js @@ -2,14 +2,18 @@ const path = require('path'); const express = require('../../../../shared/express'); const ampRouter = express.Router('amp'); -// Dirty requires -const {i18n} = require('../../../services/proxy'); +const tpl = require('@tryghost/tpl'); const errors = require('@tryghost/errors'); +// Dirty requires const urlService = require('../../../services/url'); const helpers = require('../../../services/routing/helpers'); const templateName = 'amp'; +const messages = { + pageNotFound: 'Page not found.' +}; + function _renderer(req, res, next) { res.routerOptions = { type: 'custom', @@ -23,7 +27,7 @@ function _renderer(req, res, next) { // CASE: we only support amp pages for posts that are not static pages if (!data.post || data.post.page) { - return next(new errors.NotFoundError({message: i18n.t('errors.errors.pageNotFound')})); + return next(new errors.NotFoundError({message: tpl(messages.pageNotFound)})); } // Render Call @@ -61,7 +65,7 @@ function getPostData(req, res, next) { if (!permalinks) { return next(new errors.NotFoundError({ - message: i18n.t('errors.errors.pageNotFound') + message: tpl(messages.pageNotFound) })); } diff --git a/core/frontend/apps/private-blogging/index.js b/core/frontend/apps/private-blogging/index.js index ba1b9ce7e4..43ce108340 100644 --- a/core/frontend/apps/private-blogging/index.js +++ b/core/frontend/apps/private-blogging/index.js @@ -1,11 +1,19 @@ -const {i18n} = require('../../services/proxy'); -const urlUtils = require('../../../shared/url-utils'); +const tpl = require('@tryghost/tpl'); const logging = require('@tryghost/logging'); const errors = require('@tryghost/errors'); +const urlUtils = require('../../../shared/url-utils'); const middleware = require('./lib/middleware'); const router = require('./lib/router'); const registerHelpers = require('./lib/helpers'); +const messages = { + urlCannotContainPrivateSubdir: { + error: 'private subdirectory not allowed', + description: 'Your site url in config.js cannot contain a subdirectory called private.', + help: 'Please rename the subdirectory before restarting' + } +}; + // routeKeywords.private: 'private' const PRIVATE_KEYWORD = 'private'; @@ -17,9 +25,9 @@ let checkSubdir = function checkSubdir() { if (paths.pop() === PRIVATE_KEYWORD) { logging.error(new errors.GhostError({ - message: i18n.t('errors.config.urlCannotContainPrivateSubdir.error'), - context: i18n.t('errors.config.urlCannotContainPrivateSubdir.description'), - help: i18n.t('errors.config.urlCannotContainPrivateSubdir.help') + message: tpl(messages.urlCannotContainPrivateSubdir.error), + context: tpl(messages.urlCannotContainPrivateSubdir.description), + help: tpl(messages.urlCannotContainPrivateSubdir.help) })); // @TODO: why diff --git a/core/frontend/apps/private-blogging/lib/middleware.js b/core/frontend/apps/private-blogging/lib/middleware.js index 04406e39a6..c05e5d5e3d 100644 --- a/core/frontend/apps/private-blogging/lib/middleware.js +++ b/core/frontend/apps/private-blogging/lib/middleware.js @@ -5,12 +5,17 @@ const path = require('path'); const config = require('../../../../shared/config'); const urlUtils = require('../../../../shared/url-utils'); const constants = require('@tryghost/constants'); -const {i18n} = require('../../../services/proxy'); +const tpl = require('@tryghost/tpl'); const errors = require('@tryghost/errors'); const settingsCache = require('../../../../shared/settings-cache'); // routeKeywords.private: 'private' const privateRoute = '/private/'; +const messages = { + pageNotFound: 'Page not found.', + wrongPassword: 'Wrong password' +}; + function verifySessionHash(salt, hash) { if (!salt || !hash) { return false; @@ -95,7 +100,7 @@ const privateBlogging = { // CASE: RSS is disabled for private blogging e.g. they create overhead if (req.path.match(/\/rss\/$/)) { return next(new errors.NotFoundError({ - message: i18n.t('errors.errors.pageNotFound') + message: tpl(messages.pageNotFound) })); } @@ -156,7 +161,7 @@ const privateBlogging = { return res.redirect(urlUtils.urlFor({relativeUrl: forward})); } else { res.error = { - message: i18n.t('errors.middleware.privateblogging.wrongPassword') + message: tpl(messages.wrongPassword) }; return next(); } diff --git a/core/frontend/services/routing/controllers/channel.js b/core/frontend/services/routing/controllers/channel.js index 15672f4839..f0331de176 100644 --- a/core/frontend/services/routing/controllers/channel.js +++ b/core/frontend/services/routing/controllers/channel.js @@ -1,11 +1,15 @@ const _ = require('lodash'); const debug = require('@tryghost/debug')('services:routing:controllers:channel'); -const i18n = require('../../../../shared/i18n'); +const tpl = require('@tryghost/tpl'); const errors = require('@tryghost/errors'); const security = require('@tryghost/security'); const themeEngine = require('../../theme-engine'); const helpers = require('../helpers'); +const messages = { + pageNotFound: 'Page not found.' +}; + /** * @description Channel controller. * @@ -51,7 +55,7 @@ module.exports = function channelController(req, res, next) { // CASE: requested page is greater than number of pages we have if (pathOptions.page > result.meta.pagination.pages) { return next(new errors.NotFoundError({ - message: i18n.t('errors.errors.pageNotFound') + message: tpl(messages.pageNotFound) })); } diff --git a/core/frontend/services/routing/controllers/collection.js b/core/frontend/services/routing/controllers/collection.js index f392e52e6f..f8b39b90d3 100644 --- a/core/frontend/services/routing/controllers/collection.js +++ b/core/frontend/services/routing/controllers/collection.js @@ -1,12 +1,16 @@ const _ = require('lodash'); const debug = require('@tryghost/debug')('services:routing:controllers:collection'); -const {i18n} = require('../../proxy'); +const tpl = require('@tryghost/tpl'); const errors = require('@tryghost/errors'); const security = require('@tryghost/security'); const urlService = require('../../url'); const themeEngine = require('../../theme-engine'); const helpers = require('../helpers'); +const messages = { + pageNotFound: 'Page not found.' +}; + /** * @description Collection controller. * @param {Object} req @@ -50,7 +54,7 @@ module.exports = function collectionController(req, res, next) { // CASE: requested page is greater than number of pages we have if (pathOptions.page > result.meta.pagination.pages) { return next(new errors.NotFoundError({ - message: i18n.t('errors.errors.pageNotFound') + message: tpl(messages.pageNotFound) })); } diff --git a/core/frontend/services/routing/middlewares/page-param.js b/core/frontend/services/routing/middlewares/page-param.js index f5d475dc51..5e05388771 100644 --- a/core/frontend/services/routing/middlewares/page-param.js +++ b/core/frontend/services/routing/middlewares/page-param.js @@ -1,7 +1,11 @@ -const i18n = require('../../../../shared/i18n'); +const tpl = require('@tryghost/tpl'); const errors = require('@tryghost/errors'); const urlUtils = require('../../../../shared/url-utils'); +const messages = { + pageNotFound: 'Page not found.' +}; + /** * @description Middleware, which validates and interprets the page param e.g. /page/1 * @param {Object} req @@ -21,7 +25,7 @@ module.exports = function handlePageParam(req, res, next, page) { return urlUtils.redirect301(res, req.originalUrl.replace(pageRegex, '/')); } else if (page < 1 || isNaN(page)) { return next(new errors.NotFoundError({ - message: i18n.t('errors.errors.pageNotFound') + message: tpl(messages.pageNotFound) })); } else { req.params.page = page; diff --git a/core/server/services/redirects/settings.js b/core/server/services/redirects/settings.js index 2006d24d6e..18408d3240 100644 --- a/core/server/services/redirects/settings.js +++ b/core/server/services/redirects/settings.js @@ -3,15 +3,17 @@ const path = require('path'); const moment = require('moment-timezone'); const yaml = require('js-yaml'); const Promise = require('bluebird'); -const validation = require('./validation'); -const tpl = require('@tryghost/tpl'); -const config = require('../../../shared/config'); +const tpl = require('@tryghost/tpl'); const errors = require('@tryghost/errors'); +const validation = require('./validation'); +const config = require('../../../shared/config'); + const messages = { jsonParse: 'Could not parse JSON: {context}.', - yamlParse: 'YAML input cannot be a plain string. Check the format of your YAML file.' + yamlParse: 'YAML input cannot be a plain string. Check the format of your YAML file.', + yamlParseHelp: 'https://ghost.org/docs/themes/routing/#redirects' }; /** @@ -71,8 +73,8 @@ const parseRedirectsFile = (content, ext) => { // Here we check if the user made this mistake. if (typeof configYaml === 'string') { throw new errors.BadRequestError({ - message: messages.yamlParse, - help: 'https://ghost.org/docs/themes/routing/#redirects' + message: tpl(messages.yamlParse), + help: tpl(messages.yamlParseHelp) }); } diff --git a/core/server/services/redirects/validation.js b/core/server/services/redirects/validation.js index 7ecf46df58..4975276935 100644 --- a/core/server/services/redirects/validation.js +++ b/core/server/services/redirects/validation.js @@ -1,10 +1,11 @@ const _ = require('lodash'); +const tpl = require('@tryghost/tpl'); const errors = require('@tryghost/errors'); const messages = { - redirectsWrongFormat: 'Incorrect redirects file format.' + redirectsWrongFormat: 'Incorrect redirects file format.', + redirectsHelp: 'https://ghost.org/docs/themes/routing/#redirects' }; - /** * Redirects are file based at the moment, but they will live in the database in the future. * See V2 of https://github.com/TryGhost/Ghost/issues/7707. @@ -12,17 +13,17 @@ const messages = { const validate = (redirects) => { if (!_.isArray(redirects)) { throw new errors.ValidationError({ - message: messages.redirectsWrongFormat, - help: 'https://ghost.org/docs/themes/routing/#redirects' + message: tpl(messages.redirectsWrongFormat), + help: tpl(messages.redirectsHelp) }); } _.each(redirects, function (redirect) { if (!redirect.from || !redirect.to) { throw new errors.ValidationError({ - message: messages.redirectsWrongFormat, + message: tpl(messages.redirectsWrongFormat), context: redirect, - help: 'https://ghost.org/docs/themes/routing/#redirects' + help: tpl(messages.redirectsHelp) }); } }); diff --git a/core/server/services/route-settings/loader.js b/core/server/services/route-settings/loader.js index eefe258d2c..bcea91a759 100644 --- a/core/server/services/route-settings/loader.js +++ b/core/server/services/route-settings/loader.js @@ -1,11 +1,11 @@ const fs = require('fs-extra'); const path = require('path'); const debug = require('@tryghost/debug')('frontend:services:settings:settings-loader'); +const tpl = require('@tryghost/tpl'); const errors = require('@tryghost/errors'); const config = require('../../../shared/config'); const yamlParser = require('./yaml-parser'); const validate = require('./validate'); -const tpl = require('@tryghost/tpl'); const messages = { settingsLoaderError: `Error trying to load YAML setting for {setting} from '{path}'.` diff --git a/core/server/services/route-settings/validate.js b/core/server/services/route-settings/validate.js index f2356ed7f4..9dc096e5ca 100644 --- a/core/server/services/route-settings/validate.js +++ b/core/server/services/route-settings/validate.js @@ -7,7 +7,12 @@ const _private = {}; let RESOURCE_CONFIG; const messages = { - validationError: `The following definition "{at}" is invalid: {reason}` + validationError: 'The following definition "{at}" is invalid: {reason}', + invalidResourceError: 'Resource key not supported. {resourceKey}', + invalidResourceHelp: 'Please use: tag, user, post or page.', + badDatError: 'Please wrap the data definition into a custom name.', + badDataHelp: 'Example:\n data:\n my-tag:\n resource: tags\n ...\n', + authorDeprecatedError: 'Please choose a different name. We recommend not using author.' }; _private.validateTemplate = function validateTemplate(object) { @@ -58,8 +63,8 @@ _private.validateData = function validateData(object) { if (!RESOURCE_CONFIG.QUERY[resourceKey] || (Object.prototype.hasOwnProperty.call(RESOURCE_CONFIG.QUERY[resourceKey], 'internal') && RESOURCE_CONFIG.QUERY[resourceKey].internal === true)) { throw new errors.ValidationError({ - message: `Resource key not supported. ${resourceKey}`, - help: 'Please use: tag, user, post or page.' + message: tpl(messages.invalidResourceError, {resourceKey}), + help: tpl(messages.invalidResourceHelp) }); } @@ -102,15 +107,15 @@ _private.validateData = function validateData(object) { // CASE: a name is required to define the data longform if (['resource', 'type', 'limit', 'order', 'include', 'filter', 'status', 'visibility', 'slug', 'redirect'].indexOf(key) !== -1) { throw new errors.ValidationError({ - message: 'Please wrap the data definition into a custom name.', - help: 'Example:\n data:\n my-tag:\n resource: tags\n ...\n' + message: tpl(messages.badDataError), + help: tpl(messages.badDataHelp) }); } // @NOTE: We disallow author, because {{author}} is deprecated. if (key === 'author') { throw new errors.ValidationError({ - message: 'Please choose a different name. We recommend not using author.' + message: tpl(messages.authorDeprecatedError) }); } diff --git a/core/server/services/route-settings/yaml-parser.js b/core/server/services/route-settings/yaml-parser.js index 3df09bacf6..6b0a539efa 100644 --- a/core/server/services/route-settings/yaml-parser.js +++ b/core/server/services/route-settings/yaml-parser.js @@ -4,10 +4,8 @@ const tpl = require('@tryghost/tpl'); const errors = require('@tryghost/errors'); const messages = { - yamlParsing: { - error: 'Could not parse {file}: {context}.', - help: 'Check your {file} file for typos and fix the named issues.' - } + error: 'Could not parse {file}: {context}.', + help: 'Check your {file} file for typos and fix the named issues.' }; /** @@ -28,11 +26,11 @@ module.exports = function parseYaml(file, fileName) { // `reason` property as well as in the message. // As the file uploaded is invalid, the person uploading must fix this - it's a 4xx error throw new errors.IncorrectUsageError({ - message: tpl(messages.yamlParsing.error, {file: fileName, context: error.reason}), + message: tpl(messages.error, {file: fileName, context: error.reason}), code: 'YAML_PARSER_ERROR', context: error.message, err: error, - help: tpl(messages.yamlParsing.help, {file: fileName}) + help: tpl(messages.help, {file: fileName}) }); } };