mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-04-15 03:01:37 -05:00
🐛 Fixed translations not being picked up in newsletters without reboot (#21549)
ref https://ghost.org/changelog/internationalization/ - this fixes an error in which changing the language (or sliding the i18n toggle) didn't correctly update email-service. --------- Co-authored-by: Sag <guptazy@gmail.com>
This commit is contained in:
parent
79f41dc679
commit
274f2aa8d3
3 changed files with 67 additions and 2 deletions
|
@ -1,5 +1,7 @@
|
|||
const debug = require('@tryghost/debug')('i18n');
|
||||
const logging = require('@tryghost/logging');
|
||||
const url = require('../../api/endpoints/utils/serializers/output/utils/url');
|
||||
const events = require('../../lib/common/events');
|
||||
|
||||
class EmailServiceWrapper {
|
||||
getPostUrl(post) {
|
||||
|
@ -49,8 +51,25 @@ class EmailServiceWrapper {
|
|||
const mailgunClient = new MailgunClient({
|
||||
config: configService, settings: settingsCache
|
||||
});
|
||||
const i18nLanguage = settingsCache.get('locale') || 'en';
|
||||
const i18nLanguage = labs.isSet('i18n') ? settingsCache.get('locale') || 'en' : 'en';
|
||||
const i18n = i18nLib(i18nLanguage, 'newsletter');
|
||||
|
||||
events.on('settings.labs.edited', () => {
|
||||
if (labs.isSet('i18n')) {
|
||||
debug('labs i18n enabled, updating i18n to', settingsCache.get('locale'));
|
||||
i18n.changeLanguage(settingsCache.get('locale'));
|
||||
} else {
|
||||
debug('labs i18n disabled, updating i18n to en');
|
||||
i18n.changeLanguage('en');
|
||||
}
|
||||
});
|
||||
|
||||
events.on('settings.locale.edited', (model) => {
|
||||
if (labs.isSet('i18n')) {
|
||||
debug('locale changed, updating i18n to', model.get('value'));
|
||||
i18n.changeLanguage(model.get('value'));
|
||||
}
|
||||
});
|
||||
|
||||
const mailgunEmailProvider = new MailgunEmailProvider({
|
||||
mailgunClient,
|
||||
|
|
46
ghost/core/test/e2e-browser/admin/i18n.spec.js
Normal file
46
ghost/core/test/e2e-browser/admin/i18n.spec.js
Normal file
|
@ -0,0 +1,46 @@
|
|||
const {expect} = require('@playwright/test');
|
||||
const test = require('../fixtures/ghost-test');
|
||||
const {createPostDraft} = require('../utils');
|
||||
|
||||
/**
|
||||
* @param {import('@playwright/test').Page} page
|
||||
*/
|
||||
|
||||
test.describe('i18n', () => {
|
||||
test.describe('Newsletter', () => {
|
||||
test('changing the site language immediately translates strings in newsletters', async ({sharedPage}) => {
|
||||
await sharedPage.goto('/ghost/#/settings/publication-language');
|
||||
const section = sharedPage.getByTestId('publication-language');
|
||||
await section.getByRole('button', {name: 'Edit'}).click();
|
||||
const input = section.getByPlaceholder('Site language');
|
||||
await input.fill('fr');
|
||||
await section.getByRole('button', {name: 'Save'}).click();
|
||||
|
||||
const labsSection = sharedPage.getByTestId('labs');
|
||||
await labsSection.getByRole('button', {name: 'Open'}).click();
|
||||
let portalLabel = labsSection.getByText('Portal translation');
|
||||
let portalToggle = portalLabel.locator('..').locator('..').locator('..').getByRole('switch');
|
||||
await portalToggle.click();
|
||||
|
||||
const postData = {
|
||||
title: 'Publish and email post',
|
||||
body: 'This is my post body.'
|
||||
};
|
||||
|
||||
await sharedPage.goto('/ghost');
|
||||
await createPostDraft(sharedPage, postData);
|
||||
|
||||
// click the publish-preview button
|
||||
await sharedPage.locator('[data-test-button="publish-preview"]').first().click();
|
||||
// wait for the preview to load
|
||||
await sharedPage.waitForSelector('[data-test-button="email-preview"]');
|
||||
await sharedPage.locator('[data-test-button="email-preview"]').first().click();
|
||||
|
||||
await sharedPage.waitForTimeout(1000);
|
||||
|
||||
const metaText = await sharedPage.frameLocator('iframe.gh-pe-iframe').locator('td.post-meta').first().textContent();
|
||||
expect(metaText).toContain('Par Joe Bloggs');
|
||||
expect(metaText).not.toContain('By Joe Bloggs');
|
||||
});
|
||||
});
|
||||
});
|
|
@ -427,7 +427,7 @@ test.describe('Publishing', () => {
|
|||
await sharedPage.goto('/ghost');
|
||||
await createPostDraft(sharedPage, postData);
|
||||
const editorUrl = await sharedPage.url();
|
||||
|
||||
|
||||
// Schedule the post to publish asap (by setting it to 00:00, it will get auto corrected to the minimum time possible - 5 seconds in the future)
|
||||
await publishPost(sharedPage, {type: 'send', time: '00:00'});
|
||||
await closePublishFlow(sharedPage);
|
||||
|
|
Loading…
Add table
Reference in a new issue