mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00:14 -05:00
Removed i18n from frontend theme code
- slowly slowly removing the @deprecated i18n code from everywhere in favour of tpl
This commit is contained in:
parent
10aad8db7e
commit
dda884ee4f
3 changed files with 29 additions and 14 deletions
|
@ -2,8 +2,12 @@
|
||||||
const templates = {};
|
const templates = {};
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const errors = require('@tryghost/errors');
|
const errors = require('@tryghost/errors');
|
||||||
|
const tpl = require('@tryghost/tpl');
|
||||||
const hbs = require('../engine');
|
const hbs = require('../engine');
|
||||||
const i18n = require('../../../../shared/i18n');
|
|
||||||
|
const messages = {
|
||||||
|
templateNotFound: 'Template {name} not found.'
|
||||||
|
};
|
||||||
|
|
||||||
// Execute a template helper
|
// Execute a template helper
|
||||||
// All template helpers are register as partial view.
|
// All template helpers are register as partial view.
|
||||||
|
@ -12,7 +16,7 @@ templates.execute = function execute(name, context, data) {
|
||||||
|
|
||||||
if (partial === undefined) {
|
if (partial === undefined) {
|
||||||
throw new errors.IncorrectUsageError({
|
throw new errors.IncorrectUsageError({
|
||||||
message: i18n.t('warnings.helpers.template.templateNotFound', {name: name})
|
message: tpl(messages.templateNotFound, {name: name})
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,18 @@
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const hbs = require('./engine');
|
const hbs = require('./engine');
|
||||||
const urlUtils = require('../../../shared/url-utils');
|
const urlUtils = require('../../../shared/url-utils');
|
||||||
const {i18n, api} = require('../proxy');
|
const {api} = require('../proxy');
|
||||||
const errors = require('@tryghost/errors');
|
const errors = require('@tryghost/errors');
|
||||||
|
const tpl = require('@tryghost/tpl');
|
||||||
const settingsCache = require('../../../shared/settings-cache');
|
const settingsCache = require('../../../shared/settings-cache');
|
||||||
const labs = require('../../../server/services/labs');
|
const labs = require('../../../server/services/labs');
|
||||||
const activeTheme = require('./active');
|
const activeTheme = require('./active');
|
||||||
const preview = require('./preview');
|
const preview = require('./preview');
|
||||||
|
|
||||||
|
const messages = {
|
||||||
|
missingTheme: 'The currently active theme "{theme}" is missing.'
|
||||||
|
};
|
||||||
|
|
||||||
// ### Ensure Active Theme
|
// ### Ensure Active Theme
|
||||||
// Ensure there's a properly set & mounted active theme before attempting to serve a site request
|
// Ensure there's a properly set & mounted active theme before attempting to serve a site request
|
||||||
// If there is no active theme, throw an error
|
// If there is no active theme, throw an error
|
||||||
|
@ -19,7 +24,7 @@ function ensureActiveTheme(req, res, next) {
|
||||||
return next(new errors.InternalServerError({
|
return next(new errors.InternalServerError({
|
||||||
// We use the settingsCache here, because the setting will be set,
|
// We use the settingsCache here, because the setting will be set,
|
||||||
// even if the theme itself is not usable because it is invalid or missing.
|
// even if the theme itself is not usable because it is invalid or missing.
|
||||||
message: i18n.t('errors.middleware.themehandler.missingTheme', {theme: settingsCache.get('active_theme')})
|
message: tpl(messages.missingTheme, {theme: settingsCache.get('active_theme')})
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,21 @@
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const debug = require('@tryghost/debug')('themes');
|
const debug = require('@tryghost/debug')('themes');
|
||||||
const i18n = require('../../../shared/i18n');
|
|
||||||
const logging = require('@tryghost/logging');
|
const logging = require('@tryghost/logging');
|
||||||
const errors = require('@tryghost/errors');
|
const errors = require('@tryghost/errors');
|
||||||
|
const tpl = require('@tryghost/tpl');
|
||||||
const themeLoader = require('./loader');
|
const themeLoader = require('./loader');
|
||||||
const bridge = require('../../../bridge');
|
const bridge = require('../../../bridge');
|
||||||
const validate = require('./validate');
|
const validate = require('./validate');
|
||||||
const list = require('./list');
|
const list = require('./list');
|
||||||
const settingsCache = require('../../../shared/settings-cache');
|
const settingsCache = require('../../../shared/settings-cache');
|
||||||
|
|
||||||
|
const messages = {
|
||||||
|
missingTheme: 'The currently active theme "{theme}" is missing.',
|
||||||
|
themeCannotBeActivated: '{themeName} cannot be activated because it is not currently installed.',
|
||||||
|
invalidTheme: 'The currently active theme "{theme}" is invalid.',
|
||||||
|
themeHasErrors: 'The currently active theme "{theme}" has errors, but will still work.'
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
// Init themes module
|
// Init themes module
|
||||||
// TODO: move this once we're clear what needs to happen here
|
// TODO: move this once we're clear what needs to happen here
|
||||||
|
@ -26,7 +33,7 @@ module.exports = {
|
||||||
.then(function validationSuccess(checkedTheme) {
|
.then(function validationSuccess(checkedTheme) {
|
||||||
if (!validate.canActivate(checkedTheme)) {
|
if (!validate.canActivate(checkedTheme)) {
|
||||||
const checkError = new errors.ThemeValidationError({
|
const checkError = new errors.ThemeValidationError({
|
||||||
message: i18n.t('errors.middleware.themehandler.invalidTheme', {theme: activeThemeName}),
|
message: tpl(messages.invalidTheme, {theme: activeThemeName}),
|
||||||
errorDetails: Object.assign(
|
errorDetails: Object.assign(
|
||||||
_.pick(checkedTheme, ['checkedVersion', 'name', 'path', 'version']), {
|
_.pick(checkedTheme, ['checkedVersion', 'name', 'path', 'version']), {
|
||||||
errors: checkedTheme.results.error
|
errors: checkedTheme.results.error
|
||||||
|
@ -42,7 +49,7 @@ module.exports = {
|
||||||
if (checkedTheme.results.error.length) {
|
if (checkedTheme.results.error.length) {
|
||||||
logging.warn(new errors.ThemeValidationError({
|
logging.warn(new errors.ThemeValidationError({
|
||||||
errorType: 'ThemeWorksButHasErrors',
|
errorType: 'ThemeWorksButHasErrors',
|
||||||
message: i18n.t('errors.middleware.themehandler.themeHasErrors', {theme: activeThemeName}),
|
message: tpl(messages.themeHasErrors, {theme: activeThemeName}),
|
||||||
errorDetails: Object.assign(
|
errorDetails: Object.assign(
|
||||||
_.pick(checkedTheme, ['checkedVersion', 'name', 'path', 'version']), {
|
_.pick(checkedTheme, ['checkedVersion', 'name', 'path', 'version']), {
|
||||||
errors: checkedTheme.results.error
|
errors: checkedTheme.results.error
|
||||||
|
@ -60,13 +67,12 @@ module.exports = {
|
||||||
.catch(function (err) {
|
.catch(function (err) {
|
||||||
if (err instanceof errors.NotFoundError) {
|
if (err instanceof errors.NotFoundError) {
|
||||||
// CASE: active theme is missing, we don't want to exit because the admin panel will still work
|
// CASE: active theme is missing, we don't want to exit because the admin panel will still work
|
||||||
err.message = i18n.t('errors.middleware.themehandler.missingTheme', {theme: activeThemeName});
|
err.message = tpl(messages.missingTheme, {theme: activeThemeName});
|
||||||
logging.error(err);
|
|
||||||
} else {
|
|
||||||
// CASE: theme threw an odd error, we don't want to exit because the admin panel will still work
|
|
||||||
// This is the absolute catch-all, at this point, we do not know what went wrong!
|
|
||||||
logging.error(err);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CASE: theme threw an odd error, we don't want to exit because the admin panel will still work
|
||||||
|
// This is the absolute catch-all, at this point, we do not know what went wrong!
|
||||||
|
logging.error(err);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
getJSON: require('./to-json'),
|
getJSON: require('./to-json'),
|
||||||
|
@ -75,7 +81,7 @@ module.exports = {
|
||||||
|
|
||||||
if (!loadedTheme) {
|
if (!loadedTheme) {
|
||||||
return Promise.reject(new errors.ValidationError({
|
return Promise.reject(new errors.ValidationError({
|
||||||
message: i18n.t('notices.data.validation.index.themeCannotBeActivated', {themeName: themeName}),
|
message: tpl(messages.themeCannotBeActivated, {themeName: themeName}),
|
||||||
errorDetails: themeName
|
errorDetails: themeName
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue