Skip to content

Commit

Permalink
try building, probably fail lint.
Browse files Browse the repository at this point in the history
  • Loading branch information
cathysarisky committed Oct 28, 2024
1 parent 3afc818 commit c1100c8
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class EmailServiceWrapper {
const limitService = require('../limits');
const labs = require('../../../shared/labs');
const emailAddressService = require('../email-address');

const i18nLib = require('@tryghost/i18n');
const mobiledocLib = require('../../lib/mobiledoc');
const lexicalLib = require('../../lib/lexical');
const urlUtils = require('../../../shared/url-utils');
Expand All @@ -49,6 +49,8 @@ class EmailServiceWrapper {
const mailgunClient = new MailgunClient({
config: configService, settings: settingsCache
});
const i18nLanguage = settingsCache.get('locale') || 'en';
const i18n = i18nLib(i18nLanguage, 'newsletter');

const mailgunEmailProvider = new MailgunEmailProvider({
mailgunClient,
Expand All @@ -73,7 +75,8 @@ class EmailServiceWrapper {
outboundLinkTagger: memberAttribution.outboundLinkTagger,
emailAddressService: emailAddressService.service,
labs,
models: {Post}
models: {Post},
t: i18n.t.bind(i18n)
});

const sendingService = new SendingService({
Expand Down
11 changes: 9 additions & 2 deletions ghost/core/core/server/services/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const debug = require('@tryghost/debug')('i18n');

/** @type {import('i18next').i18n} */
let i18nInstance;

let i18nInstanceNewsletter;
module.exports.init = function () {
const i18n = require('@tryghost/i18n');
const events = require('../lib/common/events');
Expand All @@ -14,13 +14,19 @@ module.exports.init = function () {
if (labs.isSet('i18n')) {
locale = settingsCache.get('locale');
}
i18nInstance = i18n(locale, 'ghost');
i18nInstanceNewsletter = i18n(locale, 'newsletter');

module.exports = i18nInstance = i18n(locale, 'ghost');
module.exports = {
i18nInstance,
i18nInstanceNewsletter
};

events.on('settings.labs.edited', () => {
if (labs.isSet('i18n')) {
debug('labs i18n enabled, updating i18n to', settingsCache.get('locale'));
i18nInstance.changeLanguage(settingsCache.get('locale'));
i18nInstanceNewsletter.changeLanguage(settingsCache.get('locale'));
} else {
debug('labs i18n disabled, updating i18n to en');
i18nInstance.changeLanguage('en');
Expand All @@ -31,6 +37,7 @@ module.exports.init = function () {
if (labs.isSet('i18n')) {
debug('locale changed, updating i18n to', model.get('value'));
i18nInstance.changeLanguage(model.get('value'));
i18nInstanceNewsletter.changeLanguage(model.get('value'));
}
});
};
15 changes: 0 additions & 15 deletions ghost/email-service/i18n-setup.js

This file was deleted.

11 changes: 7 additions & 4 deletions ghost/email-service/lib/EmailRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const tpl = require('@tryghost/tpl');
const {EmailAddressParser} = require('@tryghost/email-addresses');
const {registerHelpers} = require('./helpers/register-helpers');
const crypto = require('crypto');
const {t, locale} = require('../i18n-setup');

const messages = {
subscriptionStatus: {
Expand Down Expand Up @@ -133,6 +132,7 @@ class EmailRenderer {
#emailAddressService;
#labs;
#models;
#t;

/**
* @param {object} dependencies
Expand All @@ -153,6 +153,7 @@ class EmailRenderer {
* @param {object} dependencies.outboundLinkTagger
* @param {object} dependencies.labs
* @param {{Post: object}} dependencies.models
*
*/
constructor({
settingsCache,
Expand All @@ -169,7 +170,8 @@ class EmailRenderer {
emailAddressService,
outboundLinkTagger,
labs,
models
models,
t
}) {
this.#settingsCache = settingsCache;
this.#settingsHelpers = settingsHelpers;
Expand All @@ -186,8 +188,9 @@ class EmailRenderer {
this.#outboundLinkTagger = outboundLinkTagger;
this.#labs = labs;
this.#models = models;
this.#t = t;
}

getSubject(post, isTestEmail = false) {
const subject = post.related('posts_meta')?.get('email_subject') || post.get('title');
return isTestEmail ? `[TEST] ${subject}` : subject;
Expand Down Expand Up @@ -775,7 +778,7 @@ class EmailRenderer {
this.#handlebars = require('handlebars').create();

// Register helpers
registerHelpers(this.#handlebars, labs);
registerHelpers(this.#handlebars, labs, this.#t);

// Partials
const cssPartialSource = await fs.readFile(path.join(__dirname, './email-templates/partials/', `styles.hbs`), 'utf8');
Expand Down
6 changes: 2 additions & 4 deletions ghost/email-service/lib/helpers/register-helpers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
registerHelpers(handlebars, labs) {
registerHelpers(handlebars, labs, thist) {
handlebars.registerHelper('if', function (conditional, options) {
if (conditional) {
return options.fn(this);
Expand Down Expand Up @@ -51,10 +51,8 @@ module.exports = {
return options.inverse(this);
}
});

handlebars.registerHelper('t', function (key, options) {
let i18n = require('../../i18n-setup');
return i18n.t(key, options);
return thist(key, options);
});
}
};
3 changes: 1 addition & 2 deletions ghost/email-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
},
"files": [
"index.js",
"lib",
"i18n-setup.js"
"lib"
],
"devDependencies": {
"c8": "8.0.1",
Expand Down

0 comments on commit c1100c8

Please sign in to comment.