mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00:14 -05:00
Removed remaining use of i18n from core/frontend
- i18n is an old pattern we are getting rid of in favour of tpl - after removing i18n from helpers, there wasn't many usages of i18n left in the frontend, this removes whats left! - this was done on a branch at the same time as Naz's commits removing i18n from the settings-related files - hence some of these changes are minor amends to add additional messages/change names, rather than just straightup i18n->tpl - it's a merge of both our refactors :)
This commit is contained in:
parent
870bf27394
commit
0db7ef849c
11 changed files with 78 additions and 43 deletions
|
@ -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)
|
||||
}));
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}));
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
}));
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
@ -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}'.`
|
||||
|
|
|
@ -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)
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -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})
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue