From 7c1c252e6bd974e58aa5a56e62a04aa461aadf2b Mon Sep 17 00:00:00 2001 From: natinho68 Date: Tue, 15 Sep 2026 21:17:17 +0200 Subject: [PATCH] feat(notifications): localize the event line of notifications The event line ("New Movie Request", "Movie Request Now Available", ...) was built as a hardcoded English string by the notification producers, so every agent printed it in English no matter the recipient's locale, right next to fields that were already translated. Producers now record which message applies, along with the raw values it needs (is4k, media type, issue type), and each agent renders that line in its own recipient's locale, the same way webpush already builds its body. The webhook payload keeps the English wording it has always exposed: the notification manager derives `event` from the new message before handing the payload to the agents. --- server/entity/MediaRequest.ts | 31 ++-- server/i18n/eventMessages.test.ts | 136 ++++++++++++++++++ server/i18n/eventMessages.ts | 65 +++++++++ server/i18n/locale/en.json | 16 +++ server/lib/notifications/agents/agent.ts | 6 + server/lib/notifications/agents/discord.ts | 6 +- server/lib/notifications/agents/email.ts | 6 +- server/lib/notifications/agents/gotify.ts | 8 +- server/lib/notifications/agents/ntfy.ts | 10 +- server/lib/notifications/agents/pushbullet.ts | 6 +- server/lib/notifications/agents/pushover.ts | 6 +- server/lib/notifications/agents/slack.ts | 10 +- server/lib/notifications/agents/telegram.ts | 4 +- server/lib/notifications/index.ts | 8 ++ server/subscriber/IssueCommentSubscriber.ts | 11 +- server/subscriber/IssueSubscriber.ts | 30 ++-- server/subscriber/MediaRequestSubscriber.ts | 13 +- 17 files changed, 310 insertions(+), 62 deletions(-) create mode 100644 server/i18n/eventMessages.test.ts create mode 100644 server/i18n/eventMessages.ts diff --git a/server/entity/MediaRequest.ts b/server/entity/MediaRequest.ts index c08b5cbbc3..e1ea78c9cc 100644 --- a/server/entity/MediaRequest.ts +++ b/server/entity/MediaRequest.ts @@ -8,6 +8,8 @@ import { } from '@server/constants/media'; import { getRepository } from '@server/datasource'; import OverrideRule from '@server/entity/OverrideRule'; +import type { NotificationEventMessage } from '@server/i18n/eventMessages'; +import eventMessages from '@server/i18n/eventMessages'; import type { MediaRequestBody } from '@server/interfaces/api/requestInterfaces'; import notificationManager, { Notification } from '@server/lib/notifications'; import { Permission } from '@server/lib/permissions'; @@ -786,44 +788,43 @@ export class MediaRequest { const tmdb = new TheMovieDb(); try { - const mediaType = entity.type === MediaType.MOVIE ? 'Movie' : 'Series'; - let event: string | undefined; + let descriptor: NotificationEventMessage['descriptor'] | undefined; let notifyAdmin = true; let notifySystem = true; switch (type) { case Notification.MEDIA_AVAILABLE: - event = `${entity.is4k ? '4K ' : ''}${mediaType} Now Available`; + descriptor = eventMessages.mediaNowAvailable; notifyAdmin = false; break; case Notification.MEDIA_APPROVED: - event = `${entity.is4k ? '4K ' : ''}${mediaType} Request Approved`; + descriptor = eventMessages.mediaRequestApproved; notifyAdmin = false; break; case Notification.MEDIA_DECLINED: - event = `${entity.is4k ? '4K ' : ''}${mediaType} Request Declined`; + descriptor = eventMessages.mediaRequestDeclined; notifyAdmin = false; break; case Notification.MEDIA_PENDING: - event = `New ${entity.is4k ? '4K ' : ''}${mediaType} Request`; + descriptor = eventMessages.newMediaRequest; break; case Notification.MEDIA_AUTO_REQUESTED: - event = `${ - entity.is4k ? '4K ' : '' - }${mediaType} Request Automatically Submitted`; + descriptor = eventMessages.mediaRequestAutoSubmitted; notifyAdmin = false; notifySystem = false; break; case Notification.MEDIA_AUTO_APPROVED: - event = `${ - entity.is4k ? '4K ' : '' - }${mediaType} Request Automatically Approved`; + descriptor = eventMessages.mediaRequestAutoApproved; break; case Notification.MEDIA_FAILED: - event = `${entity.is4k ? '4K ' : ''}${mediaType} Request Failed`; + descriptor = eventMessages.mediaRequestFailed; break; } + const eventMessage = descriptor + ? { descriptor, is4k: entity.is4k, mediaType: entity.type } + : undefined; + if (entity.type === MediaType.MOVIE) { const movie = await tmdb.getMovie({ movieId: media.tmdbId }); notificationManager.sendNotification(type, { @@ -832,7 +833,7 @@ export class MediaRequest { notifyAdmin, notifySystem, notifyUser: notifyAdmin ? undefined : entity.requestedBy, - event, + eventMessage, subject: `${movie.title}${ movie.release_date ? ` (${movie.release_date.slice(0, 4)})` : '' }`, @@ -851,7 +852,7 @@ export class MediaRequest { notifyAdmin, notifySystem, notifyUser: notifyAdmin ? undefined : entity.requestedBy, - event, + eventMessage, subject: `${tv.name}${ tv.first_air_date ? ` (${tv.first_air_date.slice(0, 4)})` : '' }`, diff --git a/server/i18n/eventMessages.test.ts b/server/i18n/eventMessages.test.ts new file mode 100644 index 0000000000..da8bd240a3 --- /dev/null +++ b/server/i18n/eventMessages.test.ts @@ -0,0 +1,136 @@ +import { IssueType } from '@server/constants/issue'; +import { MediaType } from '@server/constants/media'; +import { initI18n } from '@server/i18n'; +import type { NotificationEventMessage } from '@server/i18n/eventMessages'; +import eventMessages, { formatEvent } from '@server/i18n/eventMessages'; +import assert from 'node:assert/strict'; +import { before, describe, it } from 'node:test'; + +describe('formatEvent', () => { + before(() => { + initI18n(); + }); + + // The webhook payload has always exposed these exact English strings, so they + // must survive the move to translatable messages. + const englishCases: [string, NotificationEventMessage][] = [ + [ + 'Movie Now Available', + { + descriptor: eventMessages.mediaNowAvailable, + mediaType: MediaType.MOVIE, + }, + ], + [ + '4K Series Now Available', + { + descriptor: eventMessages.mediaNowAvailable, + mediaType: MediaType.TV, + is4k: true, + }, + ], + [ + 'Series Request Now Available', + { + descriptor: eventMessages.mediaRequestNowAvailable, + mediaType: MediaType.TV, + }, + ], + [ + 'Movie Request Approved', + { + descriptor: eventMessages.mediaRequestApproved, + mediaType: MediaType.MOVIE, + }, + ], + [ + '4K Movie Request Declined', + { + descriptor: eventMessages.mediaRequestDeclined, + mediaType: MediaType.MOVIE, + is4k: true, + }, + ], + [ + 'New 4K Movie Request', + { + descriptor: eventMessages.newMediaRequest, + mediaType: MediaType.MOVIE, + is4k: true, + }, + ], + [ + 'Series Request Automatically Submitted', + { + descriptor: eventMessages.mediaRequestAutoSubmitted, + mediaType: MediaType.TV, + }, + ], + [ + 'Movie Request Automatically Approved', + { + descriptor: eventMessages.mediaRequestAutoApproved, + mediaType: MediaType.MOVIE, + }, + ], + [ + 'Series Request Failed', + { descriptor: eventMessages.mediaRequestFailed, mediaType: MediaType.TV }, + ], + [ + 'New Video Issue Reported', + { + descriptor: eventMessages.newIssueReported, + issueType: IssueType.VIDEO, + }, + ], + [ + 'New Issue Reported', + { + descriptor: eventMessages.newIssueReported, + issueType: IssueType.OTHER, + }, + ], + [ + 'Subtitle Issue Resolved', + { + descriptor: eventMessages.issueResolved, + issueType: IssueType.SUBTITLES, + }, + ], + [ + 'Issue Reopened', + { descriptor: eventMessages.issueReopened, issueType: IssueType.OTHER }, + ], + [ + 'New Comment on Audio Issue', + { + descriptor: eventMessages.newIssueComment, + issueType: IssueType.AUDIO, + }, + ], + ]; + + for (const [expected, eventMessage] of englishCases) { + it(`renders "${expected}" in English`, () => { + assert.equal(formatEvent(eventMessage, 'en'), expected); + }); + } + + it('returns undefined when there is no event message', () => { + assert.equal(formatEvent(undefined, 'en'), undefined); + }); + + it('falls back to English while a locale is still untranslated', () => { + // Weblate fills the other locales in after the strings land in en.json + const event = formatEvent( + { + descriptor: eventMessages.newMediaRequest, + mediaType: MediaType.MOVIE, + }, + 'fr' + ); + + assert.equal(event, 'New Movie Request'); + }); +}); diff --git a/server/i18n/eventMessages.ts b/server/i18n/eventMessages.ts new file mode 100644 index 0000000000..6edec22c55 --- /dev/null +++ b/server/i18n/eventMessages.ts @@ -0,0 +1,65 @@ +import { IssueType, IssueTypeName } from '@server/constants/issue'; +import { MediaType } from '@server/constants/media'; +import { defineMessages, getIntl } from '@server/i18n'; +import type { AvailableLocale } from '@server/types/languages'; + +const eventMessages = defineMessages('notifications.events', { + mediaNowAvailable: '{quality}{mediaType} Now Available', + mediaRequestNowAvailable: '{quality}{mediaType} Request Now Available', + mediaRequestApproved: '{quality}{mediaType} Request Approved', + mediaRequestDeclined: '{quality}{mediaType} Request Declined', + newMediaRequest: 'New {quality}{mediaType} Request', + mediaRequestAutoSubmitted: + '{quality}{mediaType} Request Automatically Submitted', + mediaRequestAutoApproved: + '{quality}{mediaType} Request Automatically Approved', + mediaRequestFailed: '{quality}{mediaType} Request Failed', + newIssueReported: 'New {issueType} Reported', + issueResolved: '{issueType} Resolved', + issueReopened: '{issueType} Reopened', + newIssueComment: 'New Comment on {issueType}', + movie: 'Movie', + series: 'Series', + issue: 'Issue', + issueTypeName: '{type} Issue', +}); + +/** + * Describes the event line of a notification in a locale-agnostic way. + * + * Producers only record which message applies and the raw values it needs, so + * that every agent can render the line in its own recipient's language. + */ +export interface NotificationEventMessage { + descriptor: { id: string; defaultMessage: string }; + is4k?: boolean; + mediaType?: MediaType; + issueType?: IssueType; +} + +export const formatEvent = ( + eventMessage: NotificationEventMessage | undefined, + locale?: AvailableLocale +): string | undefined => { + if (!eventMessage) { + return undefined; + } + + const intl = getIntl(locale); + + return intl.formatMessage(eventMessage.descriptor, { + quality: eventMessage.is4k ? '4K ' : '', + mediaType: + eventMessage.mediaType === MediaType.MOVIE + ? intl.formatMessage(eventMessages.movie) + : intl.formatMessage(eventMessages.series), + issueType: + eventMessage.issueType && eventMessage.issueType !== IssueType.OTHER + ? intl.formatMessage(eventMessages.issueTypeName, { + type: IssueTypeName[eventMessage.issueType], + }) + : intl.formatMessage(eventMessages.issue), + }); +}; + +export default eventMessages; diff --git a/server/i18n/locale/en.json b/server/i18n/locale/en.json index 459ed5fada..961a3df373 100644 --- a/server/i18n/locale/en.json +++ b/server/i18n/locale/en.json @@ -52,6 +52,22 @@ "notifications.common.series": "series", "notifications.common.viewIssue": "View Issue in {applicationTitle}", "notifications.common.viewMedia": "View Media in {applicationTitle}", + "notifications.events.issue": "Issue", + "notifications.events.issueReopened": "{issueType} Reopened", + "notifications.events.issueResolved": "{issueType} Resolved", + "notifications.events.issueTypeName": "{type} Issue", + "notifications.events.mediaNowAvailable": "{quality}{mediaType} Now Available", + "notifications.events.mediaRequestApproved": "{quality}{mediaType} Request Approved", + "notifications.events.mediaRequestAutoApproved": "{quality}{mediaType} Request Automatically Approved", + "notifications.events.mediaRequestAutoSubmitted": "{quality}{mediaType} Request Automatically Submitted", + "notifications.events.mediaRequestDeclined": "{quality}{mediaType} Request Declined", + "notifications.events.mediaRequestFailed": "{quality}{mediaType} Request Failed", + "notifications.events.mediaRequestNowAvailable": "{quality}{mediaType} Request Now Available", + "notifications.events.movie": "Movie", + "notifications.events.newIssueComment": "New Comment on {issueType}", + "notifications.events.newIssueReported": "New {issueType} Reported", + "notifications.events.newMediaRequest": "New {quality}{mediaType} Request", + "notifications.events.series": "Series", "notifications.test.message": "Check check, 1, 2, 3. Are we coming in clear?", "notifications.test.subject": "Test Notification" } diff --git a/server/lib/notifications/agents/agent.ts b/server/lib/notifications/agents/agent.ts index 952e1acf00..30b8b64a44 100644 --- a/server/lib/notifications/agents/agent.ts +++ b/server/lib/notifications/agents/agent.ts @@ -3,11 +3,17 @@ import type IssueComment from '@server/entity/IssueComment'; import type Media from '@server/entity/Media'; import type { MediaRequest } from '@server/entity/MediaRequest'; import type { User } from '@server/entity/User'; +import type { NotificationEventMessage } from '@server/i18n/eventMessages'; import type { NotificationAgentConfig } from '@server/lib/settings'; import type { Notification } from '..'; export interface NotificationPayload { + /** + * English rendering of `eventMessage`, kept for the webhook payload contract. + * Derived automatically when a notification is sent. + */ event?: string; + eventMessage?: NotificationEventMessage; subject: string; notifySystem: boolean; notifyAdmin: boolean; diff --git a/server/lib/notifications/agents/discord.ts b/server/lib/notifications/agents/discord.ts index 81da3c4c40..7b3c81b515 100644 --- a/server/lib/notifications/agents/discord.ts +++ b/server/lib/notifications/agents/discord.ts @@ -6,6 +6,7 @@ import { IssueStatus, IssueTypeName } from '@server/constants/issue'; import { getRepository } from '@server/datasource'; import { User } from '@server/entity/User'; import { getIntl } from '@server/i18n'; +import { formatEvent } from '@server/i18n/eventMessages'; import globalMessages from '@server/i18n/globalMessages'; import type { NotificationAgentDiscord } from '@server/lib/settings'; import { NotificationAgentKey, getSettings } from '@server/lib/settings'; @@ -95,6 +96,7 @@ class DiscordAgent locale?: AvailableLocale ): DiscordRichEmbed { const intl = getIntl(locale); + const event = formatEvent(payload.eventMessage, locale) ?? payload.event; const settings = getSettings(); const { applicationUrl } = settings.main; const { embedPoster } = settings.notifications.agents.discord; @@ -204,9 +206,7 @@ class DiscordAgent : undefined; return { - title: payload.event - ? `${payload.event}: ${payload.subject}` - : payload.subject, + title: event ? `${event}: ${payload.subject}` : payload.subject, url, description: payload.message, color, diff --git a/server/lib/notifications/agents/email.ts b/server/lib/notifications/agents/email.ts index 4037aa6ad8..bcbd42b39d 100644 --- a/server/lib/notifications/agents/email.ts +++ b/server/lib/notifications/agents/email.ts @@ -3,6 +3,7 @@ import { MediaType } from '@server/constants/media'; import { getRepository } from '@server/datasource'; import { User } from '@server/entity/User'; import { defineMessages, getIntl } from '@server/i18n'; +import { formatEvent } from '@server/i18n/eventMessages'; import globalMessages from '@server/i18n/globalMessages'; import PreparedEmail from '@server/lib/email'; import type { NotificationAgentEmail } from '@server/lib/settings'; @@ -96,6 +97,7 @@ class EmailAgent locale?: AvailableLocale ): EmailOptions | undefined { const intl = getIntl(locale); + const event = formatEvent(payload.eventMessage, locale) ?? payload.event; const settings = getSettings(); const { applicationUrl, applicationTitle } = settings.main; const { embedPoster } = settings.notifications.agents.email; @@ -193,7 +195,7 @@ class EmailAgent to: recipientEmail, }, locals: { - event: payload.event, + event, body, mediaName: payload.subject, mediaExtra: payload.extra ?? [], @@ -261,7 +263,7 @@ class EmailAgent to: recipientEmail, }, locals: { - event: payload.event, + event, body, issueDescription: payload.message, issueComment: payload.comment?.message, diff --git a/server/lib/notifications/agents/gotify.ts b/server/lib/notifications/agents/gotify.ts index 8384ab27a6..1d757728ac 100644 --- a/server/lib/notifications/agents/gotify.ts +++ b/server/lib/notifications/agents/gotify.ts @@ -1,5 +1,6 @@ import { IssueStatus, IssueTypeName } from '@server/constants/issue'; import { getIntl } from '@server/i18n'; +import { formatEvent } from '@server/i18n/eventMessages'; import globalMessages from '@server/i18n/globalMessages'; import type { NotificationAgentGotify } from '@server/lib/settings'; import { getSettings } from '@server/lib/settings'; @@ -51,13 +52,14 @@ class GotifyAgent ): GotifyPayload { const settings = this.getSettings(); const intl = getIntl(settings.options.locale); + const event = + formatEvent(payload.eventMessage, settings.options.locale) ?? + payload.event; const { applicationUrl, applicationTitle } = getSettings().main; const embedPoster = settings.embedPoster; const priority = settings.options.priority ?? 1; - const title = payload.event - ? `${payload.event} - ${payload.subject}` - : payload.subject; + const title = event ? `${event} - ${payload.subject}` : payload.subject; let message = payload.message ? `${payload.message} \n\n` : ''; diff --git a/server/lib/notifications/agents/ntfy.ts b/server/lib/notifications/agents/ntfy.ts index c9efcbe2f6..14e3858053 100644 --- a/server/lib/notifications/agents/ntfy.ts +++ b/server/lib/notifications/agents/ntfy.ts @@ -1,5 +1,6 @@ import { IssueStatus, IssueTypeName } from '@server/constants/issue'; import { getIntl } from '@server/i18n'; +import { formatEvent } from '@server/i18n/eventMessages'; import globalMessages from '@server/i18n/globalMessages'; import type { NotificationAgentNtfy } from '@server/lib/settings'; import { getSettings } from '@server/lib/settings'; @@ -31,6 +32,11 @@ class NtfyAgent private buildPayload(type: Notification, payload: NotificationPayload) { const settings = this.getSettings(); const intl = getIntl(settings.options.locale as AvailableLocale); + const event = + formatEvent( + payload.eventMessage, + settings.options.locale as AvailableLocale + ) ?? payload.event; const { applicationUrl } = getSettings().main; const embedPoster = settings.embedPoster; @@ -41,9 +47,7 @@ class NtfyAgent .filter((tag) => tag.length > 0); const priority = settings.options.priority ?? 3; - const title = payload.event - ? `${payload.event} - ${payload.subject}` - : payload.subject; + const title = event ? `${event} - ${payload.subject}` : payload.subject; let message = payload.message ?? ''; if (payload.request) { diff --git a/server/lib/notifications/agents/pushbullet.ts b/server/lib/notifications/agents/pushbullet.ts index 971c0b3d84..4f442de039 100644 --- a/server/lib/notifications/agents/pushbullet.ts +++ b/server/lib/notifications/agents/pushbullet.ts @@ -3,6 +3,7 @@ import { MediaStatus } from '@server/constants/media'; import { getRepository } from '@server/datasource'; import { User } from '@server/entity/User'; import { getIntl } from '@server/i18n'; +import { formatEvent } from '@server/i18n/eventMessages'; import globalMessages from '@server/i18n/globalMessages'; import type { NotificationAgentPushbullet } from '@server/lib/settings'; import { NotificationAgentKey, getSettings } from '@server/lib/settings'; @@ -48,9 +49,8 @@ class PushbulletAgent locale?: AvailableLocale ): PushbulletPayload { const intl = getIntl(locale); - const title = payload.event - ? `${payload.event} - ${payload.subject}` - : payload.subject; + const event = formatEvent(payload.eventMessage, locale) ?? payload.event; + const title = event ? `${event} - ${payload.subject}` : payload.subject; let body = payload.message ?? ''; if (payload.request) { diff --git a/server/lib/notifications/agents/pushover.ts b/server/lib/notifications/agents/pushover.ts index 065401dc49..f13149d1aa 100644 --- a/server/lib/notifications/agents/pushover.ts +++ b/server/lib/notifications/agents/pushover.ts @@ -3,6 +3,7 @@ import { MediaStatus } from '@server/constants/media'; import { getRepository } from '@server/datasource'; import { User } from '@server/entity/User'; import { getIntl } from '@server/i18n'; +import { formatEvent } from '@server/i18n/eventMessages'; import globalMessages from '@server/i18n/globalMessages'; import type { NotificationAgentPushover } from '@server/lib/settings'; import { NotificationAgentKey, getSettings } from '@server/lib/settings'; @@ -93,12 +94,13 @@ class PushoverAgent locale?: AvailableLocale ): Promise> { const intl = getIntl(locale); + const event = formatEvent(payload.eventMessage, locale) ?? payload.event; const settings = getSettings(); const { applicationUrl, applicationTitle } = settings.main; const { embedPoster } = settings.notifications.agents.pushover; - const title = payload.event ?? payload.subject; - let message = payload.event ? `${payload.subject}` : ''; + const title = event ?? payload.subject; + let message = event ? `${payload.subject}` : ''; let priority = 0; if (payload.message) { diff --git a/server/lib/notifications/agents/slack.ts b/server/lib/notifications/agents/slack.ts index 33320ff5f1..574ab56654 100644 --- a/server/lib/notifications/agents/slack.ts +++ b/server/lib/notifications/agents/slack.ts @@ -1,5 +1,6 @@ import { IssueStatus, IssueTypeName } from '@server/constants/issue'; import { getIntl } from '@server/i18n'; +import { formatEvent } from '@server/i18n/eventMessages'; import globalMessages from '@server/i18n/globalMessages'; import type { NotificationAgentSlack } from '@server/lib/settings'; import { getSettings } from '@server/lib/settings'; @@ -67,6 +68,9 @@ class SlackAgent ): SlackBlockEmbed { const settings = this.getSettings(); const intl = getIntl(settings.options.locale); + const event = + formatEvent(payload.eventMessage, settings.options.locale) ?? + payload.event; const { applicationUrl, applicationTitle } = getSettings().main; const embedPoster = settings.embedPoster; @@ -139,13 +143,13 @@ class SlackAgent const blocks: EmbedBlock[] = []; - if (payload.event) { + if (event) { blocks.push({ type: 'context', elements: [ { type: 'mrkdwn', - text: `*${payload.event}*`, + text: `*${event}*`, }, ], }); @@ -215,7 +219,7 @@ class SlackAgent } return { - text: payload.event ?? payload.subject, + text: event ?? payload.subject, blocks, }; } diff --git a/server/lib/notifications/agents/telegram.ts b/server/lib/notifications/agents/telegram.ts index 6d1bf4d83a..21b404b4c5 100644 --- a/server/lib/notifications/agents/telegram.ts +++ b/server/lib/notifications/agents/telegram.ts @@ -3,6 +3,7 @@ import { MediaStatus } from '@server/constants/media'; import { getRepository } from '@server/datasource'; import { User } from '@server/entity/User'; import { getIntl } from '@server/i18n'; +import { formatEvent } from '@server/i18n/eventMessages'; import globalMessages from '@server/i18n/globalMessages'; import type { NotificationAgentTelegram } from '@server/lib/settings'; import { NotificationAgentKey, getSettings } from '@server/lib/settings'; @@ -70,13 +71,14 @@ class TelegramAgent locale?: AvailableLocale ): Partial { const intl = getIntl(locale); + const event = formatEvent(payload.eventMessage, locale) ?? payload.event; const settings = getSettings(); const { applicationUrl, applicationTitle } = settings.main; const { embedPoster } = settings.notifications.agents.telegram; /* eslint-disable no-useless-escape */ let message = `\*${this.escapeText( - payload.event ? `${payload.event} - ${payload.subject}` : payload.subject + event ? `${event} - ${payload.subject}` : payload.subject )}\*`; if (payload.message) { message += `\n${this.escapeText(payload.message)}`; diff --git a/server/lib/notifications/index.ts b/server/lib/notifications/index.ts index b822ae6eef..7bca3eafe1 100644 --- a/server/lib/notifications/index.ts +++ b/server/lib/notifications/index.ts @@ -1,4 +1,5 @@ import type { User } from '@server/entity/User'; +import { formatEvent } from '@server/i18n/eventMessages'; import { Permission } from '@server/lib/permissions'; import logger from '@server/logger'; import type { NotificationAgent, NotificationPayload } from './agents/agent'; @@ -106,6 +107,13 @@ class NotificationManager { subject: payload.subject, }); + // Agents render the event line in their recipient's language; `event` keeps + // the English wording that the webhook payload has always exposed. + payload = { + ...payload, + event: payload.event ?? formatEvent(payload.eventMessage, 'en'), + }; + this.activeAgents.forEach((agent) => { if (agent.shouldSend()) { agent.send(type, payload); diff --git a/server/subscriber/IssueCommentSubscriber.ts b/server/subscriber/IssueCommentSubscriber.ts index 0c97c4c5f1..a801f26365 100644 --- a/server/subscriber/IssueCommentSubscriber.ts +++ b/server/subscriber/IssueCommentSubscriber.ts @@ -1,10 +1,10 @@ import TheMovieDb from '@server/api/themoviedb'; -import { IssueType, IssueTypeName } from '@server/constants/issue'; import { MediaType } from '@server/constants/media'; import { getRepository } from '@server/datasource'; import IssueComment from '@server/entity/IssueComment'; import Media from '@server/entity/Media'; import { User } from '@server/entity/User'; +import eventMessages from '@server/i18n/eventMessages'; import notificationManager, { Notification } from '@server/lib/notifications'; import { Permission } from '@server/lib/permissions'; import logger from '@server/logger'; @@ -60,11 +60,10 @@ export class IssueCommentSubscriber implements EntitySubscriberInterface { } notificationManager.sendNotification(type, { - event: - type === Notification.ISSUE_CREATED - ? `New ${ - entity.issueType !== IssueType.OTHER - ? `${IssueTypeName[entity.issueType]} ` - : '' - }Issue Reported` - : type === Notification.ISSUE_RESOLVED - ? `${ - entity.issueType !== IssueType.OTHER - ? `${IssueTypeName[entity.issueType]} ` - : '' - }Issue Resolved` - : `${ - entity.issueType !== IssueType.OTHER - ? `${IssueTypeName[entity.issueType]} ` - : '' - }Issue Reopened`, + eventMessage: { + descriptor: + type === Notification.ISSUE_CREATED + ? eventMessages.newIssueReported + : type === Notification.ISSUE_RESOLVED + ? eventMessages.issueResolved + : eventMessages.issueReopened, + issueType: entity.issueType, + }, subject: title, message: firstComment.message, issue: entity, diff --git a/server/subscriber/MediaRequestSubscriber.ts b/server/subscriber/MediaRequestSubscriber.ts index 77e70cfa11..6d0981ea36 100644 --- a/server/subscriber/MediaRequestSubscriber.ts +++ b/server/subscriber/MediaRequestSubscriber.ts @@ -17,6 +17,7 @@ import Media from '@server/entity/Media'; import { MediaRequest } from '@server/entity/MediaRequest'; import Season from '@server/entity/Season'; import SeasonRequest from '@server/entity/SeasonRequest'; +import eventMessages from '@server/i18n/eventMessages'; import notificationManager, { Notification } from '@server/lib/notifications'; import { getSettings } from '@server/lib/settings'; import logger from '@server/logger'; @@ -77,7 +78,11 @@ export class MediaRequestSubscriber implements EntitySubscriberInterface