Removed use of i18n in Bookshelf plugins

no issue

- i18n is eventually going away in Ghost so we want to remove uses of it
- Bookshelf plugins are also getting extraced out of Ghost so we need to
  remove all local requires
- i18n is being replaced by inline templating with strings stored in the
  `messages` object
- this commit switches out the use of i18n in the Bookshelf plugins and
  replaces the templating function with our `@tryghost/tpl` package
This commit is contained in:
Daniel Lockyer 2021-06-14 15:13:41 +01:00
parent 1ec7c70c6f
commit d783a8d2d4
No known key found for this signature in database
GPG Key ID: D21186F0B47295AD
2 changed files with 17 additions and 7 deletions

View File

@ -1,6 +1,10 @@
const debug = require('ghost-ignition').debug('models:plugins:filter');
const i18n = require('../../../shared/i18n');
const errors = require('@tryghost/errors');
const tpl = require('@tryghost/tpl');
const messages = {
errorParsing: 'Error parsing filter'
};
const RELATIONS = {
tags: {
@ -133,8 +137,8 @@ const filter = function filter(Bookshelf) {
});
} catch (err) {
throw new errors.BadRequestError({
message: i18n.t('errors.models.plugins.filter.errorParsing'),
err: err
message: tpl(messages.errorParsing),
err
});
}
}

View File

@ -3,8 +3,14 @@
// Extends Bookshelf.Model with a `fetchPage` method. Handles everything to do with paginated requests.
const _ = require('lodash');
const i18n = require('../../../shared/i18n');
const errors = require('@tryghost/errors');
const tpl = require('@tryghost/tpl');
const messages = {
pageNotFound: 'Page not found'
couldNotUnderstandRequest: 'Could not understand request.'
};
let defaults;
let paginationUtils;
@ -242,7 +248,7 @@ const pagination = function pagination(bookshelf) {
.catch(function (err) {
// e.g. offset/limit reached max allowed integer value
if (err.errno === 20 || err.errno === 1064) {
throw new errors.NotFoundError({message: i18n.t('errors.errors.pageNotFound')});
throw new errors.NotFoundError({message: tpl(messages.pageNotFound)});
}
throw err;
@ -251,8 +257,8 @@ const pagination = function pagination(bookshelf) {
// CASE: SQL syntax is incorrect
if (err.errno === 1054 || err.errno === 1) {
throw new errors.BadRequestError({
message: i18n.t('errors.models.general.sql'),
err: err
message: tpl(messages.couldNotUnderstandRequest),
err
});
}