From 86272e52df54071be956f0cddcc9b1ae152a0cbd Mon Sep 17 00:00:00 2001 From: Tasso Evangelista Date: Tue, 15 Oct 2024 23:28:21 -0300 Subject: [PATCH] refactor(i18n): Use i18next API to get a fixed t-function (#33586) --- apps/meteor/app/2fa/server/code/EmailCheck.ts | 2 +- apps/meteor/app/2fa/server/functions/resetTOTP.ts | 2 +- apps/meteor/app/livechat/server/api/v1/room.ts | 2 +- apps/meteor/server/features/EmailInbox/EmailInbox_Incoming.ts | 2 +- apps/meteor/server/features/EmailInbox/EmailInbox_Outgoing.ts | 2 +- apps/meteor/server/lib/resetUserE2EKey.ts | 2 +- apps/meteor/server/services/omnichannel-analytics/service.ts | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/apps/meteor/app/2fa/server/code/EmailCheck.ts b/apps/meteor/app/2fa/server/code/EmailCheck.ts index d947c1b30c2e3..5baf218a62bb2 100644 --- a/apps/meteor/app/2fa/server/code/EmailCheck.ts +++ b/apps/meteor/app/2fa/server/code/EmailCheck.ts @@ -38,7 +38,7 @@ export class EmailCheck implements ICodeCheck { private async send2FAEmail(address: string, random: string, user: IUser): Promise { const language = user.language || settings.get('Language') || 'en'; - const t = (s: string): string => i18n.t(s, { lng: language }); + const t = i18n.getFixedT(language); await Mailer.send({ to: address, diff --git a/apps/meteor/app/2fa/server/functions/resetTOTP.ts b/apps/meteor/app/2fa/server/functions/resetTOTP.ts index 3be8ec7c80602..84426cd4f88d8 100644 --- a/apps/meteor/app/2fa/server/functions/resetTOTP.ts +++ b/apps/meteor/app/2fa/server/functions/resetTOTP.ts @@ -22,7 +22,7 @@ const sendResetNotification = async function (uid: string): Promise { return; } - const t = (s: string): string => i18n.t(s, { lng: language }); + const t = i18n.getFixedT(language); const text = ` ${t('Your_TOTP_has_been_reset')} diff --git a/apps/meteor/app/livechat/server/api/v1/room.ts b/apps/meteor/app/livechat/server/api/v1/room.ts index 45428f6835314..00332f0f20b71 100644 --- a/apps/meteor/app/livechat/server/api/v1/room.ts +++ b/apps/meteor/app/livechat/server/api/v1/room.ts @@ -157,7 +157,7 @@ API.v1.addRoute( const visitorEmail = visitor.visitorEmails?.[0]?.address; const language = servingAgent.language || rcSettings.get('Language') || 'en'; - const t = (s: string): string => i18n.t(s, { lng: language }); + const t = i18n.getFixedT(language); const subject = t('Transcript_of_your_livechat_conversation'); options.emailTranscript = { diff --git a/apps/meteor/server/features/EmailInbox/EmailInbox_Incoming.ts b/apps/meteor/server/features/EmailInbox/EmailInbox_Incoming.ts index 0797d896f22d7..7ecb8f309b29d 100644 --- a/apps/meteor/server/features/EmailInbox/EmailInbox_Incoming.ts +++ b/apps/meteor/server/features/EmailInbox/EmailInbox_Incoming.ts @@ -22,7 +22,7 @@ import { logger } from './logger'; type FileAttachment = VideoAttachmentProps & ImageAttachmentProps & AudioAttachmentProps; const language = settings.get('Language') || 'en'; -const t = (s: string): string => i18n.t(s, { lng: language }); +const t = i18n.getFixedT(language); async function getGuestByEmail(email: string, name: string, department = ''): Promise { const guest = await LivechatVisitors.findOneGuestByEmailAddress(email); diff --git a/apps/meteor/server/features/EmailInbox/EmailInbox_Outgoing.ts b/apps/meteor/server/features/EmailInbox/EmailInbox_Outgoing.ts index 51718e4937d81..44a9e2cd6a150 100644 --- a/apps/meteor/server/features/EmailInbox/EmailInbox_Outgoing.ts +++ b/apps/meteor/server/features/EmailInbox/EmailInbox_Outgoing.ts @@ -20,7 +20,7 @@ const livechatQuoteRegExp = /^\[\s\]\(https?:\/\/.+\/live\/.+\?msg=(?.+?)\)\ const getRocketCatUser = async (): Promise => Users.findOneById('rocket.cat'); const language = settings.get('Language') || 'en'; -const t = (s: string): string => i18n.t(s, { lng: language }); +const t = i18n.getFixedT(language); // TODO: change these messages with room notifications const sendErrorReplyMessage = async (error: string, options: any) => { diff --git a/apps/meteor/server/lib/resetUserE2EKey.ts b/apps/meteor/server/lib/resetUserE2EKey.ts index 85da6e59cf607..26ac78f30ad6d 100644 --- a/apps/meteor/server/lib/resetUserE2EKey.ts +++ b/apps/meteor/server/lib/resetUserE2EKey.ts @@ -20,7 +20,7 @@ const sendResetNotification = async function (uid: string): Promise { return; } - const t = (s: string): string => i18n.t(s, { lng: language }); + const t = i18n.getFixedT(language); const text = ` ${t('Your_e2e_key_has_been_reset')} diff --git a/apps/meteor/server/services/omnichannel-analytics/service.ts b/apps/meteor/server/services/omnichannel-analytics/service.ts index 4f479d83acdd7..8b27ed4b9f578 100644 --- a/apps/meteor/server/services/omnichannel-analytics/service.ts +++ b/apps/meteor/server/services/omnichannel-analytics/service.ts @@ -160,7 +160,7 @@ export class OmnichannelAnalyticsService extends ServiceClassInternal implements return; } - const t = (s: string) => i18n.t(s, { lng: language }); + const t = i18n.getFixedT(language); const extraQuery = await callbacks.run('livechat.applyRoomRestrictions', {}); return this.overview.callAction(name, from, to, departmentId, timezone, t, extraQuery);