mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-11 02:12:21 -05:00
Replaced i18n with tpl in GhostMailer.js (#13555)
refs: #13380 - The i18n package is deprecated. It is being replaced with the tpl package.
This commit is contained in:
parent
e2aeca56e9
commit
9ccf590ddc
1 changed files with 18 additions and 10 deletions
|
@ -4,9 +4,17 @@ const _ = require('lodash');
|
|||
const validator = require('@tryghost/validator');
|
||||
const config = require('../../../shared/config');
|
||||
const errors = require('@tryghost/errors');
|
||||
const i18n = require('../../../shared/i18n');
|
||||
const tpl = require('@tryghost/tpl');
|
||||
const settingsCache = require('../../../shared/settings-cache');
|
||||
const urlUtils = require('../../../shared/url-utils');
|
||||
const messages = {
|
||||
title: 'Ghost at {domain}',
|
||||
checkEmailConfigInstructions: 'Please see {url} for instructions on configuring email.',
|
||||
failedSendingEmailError: 'Failed to send email.',
|
||||
incompleteMessageDataError: 'Incomplete message data.',
|
||||
reason: ' Reason: {reason}.',
|
||||
messageSent: 'Message sent. Double check inbox and spam folder!'
|
||||
};
|
||||
|
||||
function getDomain() {
|
||||
const domain = urlUtils.urlFor('home', true).match(new RegExp('^https?://([^/:?#]+)(?:[/:?#]|$)', 'i'));
|
||||
|
@ -25,7 +33,7 @@ function getFromAddress(requestedFromAddress) {
|
|||
|
||||
// If we do have a from address, and it's just an email
|
||||
if (validator.isEmail(address, {require_tld: false})) {
|
||||
const defaultSiteTitle = settingsCache.get('title') ? settingsCache.get('title').replace(/"/g, '\\"') : i18n.t('common.mail.title', {domain: getDomain()});
|
||||
const defaultSiteTitle = settingsCache.get('title') ? settingsCache.get('title').replace(/"/g, '\\"') : tpl(messages.title, {domain: getDomain()});
|
||||
return `"${defaultSiteTitle}" <${address}>`;
|
||||
}
|
||||
|
||||
|
@ -51,8 +59,8 @@ function createMessage(message) {
|
|||
}
|
||||
|
||||
function createMailError({message, err, ignoreDefaultMessage} = {message: ''}) {
|
||||
const helpMessage = i18n.t('errors.api.authentication.checkEmailConfigInstructions', {url: 'https://ghost.org/docs/config/#mail'});
|
||||
const defaultErrorMessage = i18n.t('errors.mail.failedSendingEmail.error');
|
||||
const helpMessage = tpl(messages.checkEmailConfigInstructions, {url: 'https://ghost.org/docs/config/#mail'});
|
||||
const defaultErrorMessage = tpl(messages.failedSendingEmailError);
|
||||
|
||||
const fullErrorMessage = defaultErrorMessage + message;
|
||||
let statusCode = (err && err.name === 'RecipientError') ? 400 : 500;
|
||||
|
@ -95,7 +103,7 @@ module.exports = class GhostMailer {
|
|||
async send(message) {
|
||||
if (!(message && message.subject && message.html && message.to)) {
|
||||
throw createMailError({
|
||||
message: i18n.t('errors.mail.incompleteMessageData.error'),
|
||||
message: tpl(messages.incompleteMessageDataError),
|
||||
ignoreDefaultMessage: true
|
||||
});
|
||||
}
|
||||
|
@ -117,7 +125,7 @@ module.exports = class GhostMailer {
|
|||
return response;
|
||||
} catch (err) {
|
||||
throw createMailError({
|
||||
message: i18n.t('errors.mail.reason', {reason: err.message || err}),
|
||||
message: tpl(messages.reason, {reason: err.message || err}),
|
||||
err
|
||||
});
|
||||
}
|
||||
|
@ -125,21 +133,21 @@ module.exports = class GhostMailer {
|
|||
|
||||
handleDirectTransportResponse(response) {
|
||||
if (!response) {
|
||||
return i18n.t('notices.mail.messageSent');
|
||||
return tpl(messages.messageSent);
|
||||
}
|
||||
|
||||
if (response.pending.length > 0) {
|
||||
throw createMailError({
|
||||
message: i18n.t('errors.mail.reason', {reason: 'Email has been temporarily rejected'})
|
||||
message: tpl(messages.reason, {reason: 'Email has been temporarily rejected'})
|
||||
});
|
||||
}
|
||||
|
||||
if (response.errors.length > 0) {
|
||||
throw createMailError({
|
||||
message: i18n.t('errors.mail.reason', {reason: response.errors[0].message})
|
||||
message: tpl(messages.reason, {reason: response.errors[0].message})
|
||||
});
|
||||
}
|
||||
|
||||
return i18n.t('notices.mail.messageSent');
|
||||
return tpl(messages.messageSent);
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue