From eb98763478463cf58fa44093cca549e95fd42844 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucien=20Akchot=C3=A9?= Date: Wed, 12 Mar 2025 15:53:39 +0100 Subject: [PATCH 1/3] use time related data in `message` key for translation --- src/pages/signin/SMSDeliveryFailurePage.tsx | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/pages/signin/SMSDeliveryFailurePage.tsx b/src/pages/signin/SMSDeliveryFailurePage.tsx index ac8d04f556fa..dca3c7b74f72 100644 --- a/src/pages/signin/SMSDeliveryFailurePage.tsx +++ b/src/pages/signin/SMSDeliveryFailurePage.tsx @@ -29,7 +29,23 @@ function SMSDeliveryFailurePage() { }, [credentials?.login]); const SMSDeliveryFailureMessage = account?.smsDeliveryFailureStatus?.message; + + type TimeData = { + days?: number; + hours?: number; + minutes?: number; + }; + + const timeData = useMemo(() => { + if (!SMSDeliveryFailureMessage) { + return null; + } + return JSON.parse(SMSDeliveryFailureMessage) as TimeData; + + }, [SMSDeliveryFailureMessage]); + const hasSMSDeliveryFailure = account?.smsDeliveryFailureStatus?.hasSMSDeliveryFailure; + const isReset = account?.smsDeliveryFailureStatus?.isReset; const errorText = useMemo(() => (account ? getLatestErrorMessage(account) : ''), [account]); @@ -48,7 +64,7 @@ function SMSDeliveryFailurePage() { - {translate('smsDeliveryFailurePage.validationFailed')} {SMSDeliveryFailureMessage} + {translate('smsDeliveryFailurePage.validationFailed')} {timeData && translate('smsDeliveryFailurePage.pleaseWaitBeforeTryingAgain', {timeData})} From 25118564cf4be0acf602654b474d3d2225c88f04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucien=20Akchot=C3=A9?= Date: Wed, 12 Mar 2025 15:54:33 +0100 Subject: [PATCH 2/3] implement time related data translation for `SMSDeliveryFailurePage` --- src/languages/en.ts | 28 ++++++++++++++++++++++++++++ src/languages/es.ts | 28 ++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/src/languages/en.ts b/src/languages/en.ts index dc55db4db924..6d874aec7c23 100755 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -1943,6 +1943,34 @@ const translations = { `We've been unable to deliver SMS messages to ${login}, so we've suspended it for 24 hours. Please try validating your number:`, validationFailed: 'Validation failed because it hasn’t been 24 hours since your last attempt.', validationSuccess: 'Your number has been validated! Click below to send a new magic sign-in code.', + pleaseWaitBeforeTryingAgain: ({timeData}: {timeData?: {days?: number, hours?: number, minutes?: number}}) => { + if (!timeData) { + return 'Please wait a moment before trying again.'; + } + + const parts = []; + if (timeData.days) { + parts.push(`${timeData.days} ${timeData.days === 1 ? 'day' : 'days'}`); + } + if (timeData.hours) { + parts.push(`${timeData.hours} ${timeData.hours === 1 ? 'hour' : 'hours'}`); + } + if (timeData.minutes) { + parts.push(`${timeData.minutes} ${timeData.minutes === 1 ? 'minute' : 'minutes'}`); + } + + let timeText; + if (parts.length === 1) { + timeText = parts.at(0); + } else if (parts.length === 2) { + timeText = parts.join(' and '); + } else { + const lastPart = parts.pop(); + timeText = `${parts.join(', ')} and ${lastPart}`; + } + + return `Please wait ${timeText} before trying again.`; + }, }, welcomeSignUpForm: { join: 'Join', diff --git a/src/languages/es.ts b/src/languages/es.ts index a88fd18f5024..38fa9edce8e1 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -1947,6 +1947,34 @@ const translations = { `No hemos podido entregar mensajes SMS a ${login}, así que lo hemos suspendido durante 24 horas. Por favor, intenta validar tu número:`, validationFailed: 'La validación falló porque no han pasado 24 horas desde tu último intento.', validationSuccess: '¡Tu número ha sido validado! Haz clic abajo para enviar un nuevo código mágico de inicio de sesión.', + pleaseWaitBeforeTryingAgain: ({timeData}: {timeData?: {days?: number, hours?: number, minutes?: number}}) => { + if (!timeData) { + return 'Por favor, espera un momento antes de intentarlo de nuevo.'; + } + + const parts = []; + if (timeData.days) { + parts.push(`${timeData.days} ${timeData.days === 1 ? 'día' : 'días'}`); + } + if (timeData.hours) { + parts.push(`${timeData.hours} ${timeData.hours === 1 ? 'hora' : 'horas'}`); + } + if (timeData.minutes) { + parts.push(`${timeData.minutes} ${timeData.minutes === 1 ? 'minuto' : 'minutos'}`); + } + + let timeText; + if (parts.length === 1) { + timeText = parts.at(0); + } else if (parts.length === 2) { + timeText = parts.join(' y '); + } else { + const lastPart = parts.pop(); + timeText = `${parts.join(', ')} y ${lastPart}`; + } + + return `Por favor, espera ${timeText} antes de intentarlo de nuevo.`; + } }, welcomeSignUpForm: { join: 'Unirse', From 8e7e6e94f017ce5f34b98a760ba8dc2b127d512f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucien=20Akchot=C3=A9?= Date: Wed, 12 Mar 2025 16:14:22 +0100 Subject: [PATCH 3/3] fix style --- src/languages/en.ts | 8 ++++---- src/languages/es.ts | 10 +++++----- src/pages/signin/SMSDeliveryFailurePage.tsx | 3 +-- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/languages/en.ts b/src/languages/en.ts index 6d874aec7c23..3b577fceca71 100755 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -1943,11 +1943,11 @@ const translations = { `We've been unable to deliver SMS messages to ${login}, so we've suspended it for 24 hours. Please try validating your number:`, validationFailed: 'Validation failed because it hasn’t been 24 hours since your last attempt.', validationSuccess: 'Your number has been validated! Click below to send a new magic sign-in code.', - pleaseWaitBeforeTryingAgain: ({timeData}: {timeData?: {days?: number, hours?: number, minutes?: number}}) => { + pleaseWaitBeforeTryingAgain: ({timeData}: {timeData?: {days?: number; hours?: number; minutes?: number}}) => { if (!timeData) { return 'Please wait a moment before trying again.'; } - + const parts = []; if (timeData.days) { parts.push(`${timeData.days} ${timeData.days === 1 ? 'day' : 'days'}`); @@ -1958,7 +1958,7 @@ const translations = { if (timeData.minutes) { parts.push(`${timeData.minutes} ${timeData.minutes === 1 ? 'minute' : 'minutes'}`); } - + let timeText; if (parts.length === 1) { timeText = parts.at(0); @@ -1968,7 +1968,7 @@ const translations = { const lastPart = parts.pop(); timeText = `${parts.join(', ')} and ${lastPart}`; } - + return `Please wait ${timeText} before trying again.`; }, }, diff --git a/src/languages/es.ts b/src/languages/es.ts index 38fa9edce8e1..53dec2b14fc0 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -1947,11 +1947,11 @@ const translations = { `No hemos podido entregar mensajes SMS a ${login}, así que lo hemos suspendido durante 24 horas. Por favor, intenta validar tu número:`, validationFailed: 'La validación falló porque no han pasado 24 horas desde tu último intento.', validationSuccess: '¡Tu número ha sido validado! Haz clic abajo para enviar un nuevo código mágico de inicio de sesión.', - pleaseWaitBeforeTryingAgain: ({timeData}: {timeData?: {days?: number, hours?: number, minutes?: number}}) => { + pleaseWaitBeforeTryingAgain: ({timeData}: {timeData?: {days?: number; hours?: number; minutes?: number}}) => { if (!timeData) { return 'Por favor, espera un momento antes de intentarlo de nuevo.'; } - + const parts = []; if (timeData.days) { parts.push(`${timeData.days} ${timeData.days === 1 ? 'día' : 'días'}`); @@ -1962,7 +1962,7 @@ const translations = { if (timeData.minutes) { parts.push(`${timeData.minutes} ${timeData.minutes === 1 ? 'minuto' : 'minutos'}`); } - + let timeText; if (parts.length === 1) { timeText = parts.at(0); @@ -1972,9 +1972,9 @@ const translations = { const lastPart = parts.pop(); timeText = `${parts.join(', ')} y ${lastPart}`; } - + return `Por favor, espera ${timeText} antes de intentarlo de nuevo.`; - } + }, }, welcomeSignUpForm: { join: 'Unirse', diff --git a/src/pages/signin/SMSDeliveryFailurePage.tsx b/src/pages/signin/SMSDeliveryFailurePage.tsx index dca3c7b74f72..953a0dfc0a8b 100644 --- a/src/pages/signin/SMSDeliveryFailurePage.tsx +++ b/src/pages/signin/SMSDeliveryFailurePage.tsx @@ -41,9 +41,8 @@ function SMSDeliveryFailurePage() { return null; } return JSON.parse(SMSDeliveryFailureMessage) as TimeData; + }, [SMSDeliveryFailureMessage]); - }, [SMSDeliveryFailureMessage]); - const hasSMSDeliveryFailure = account?.smsDeliveryFailureStatus?.hasSMSDeliveryFailure; const isReset = account?.smsDeliveryFailureStatus?.isReset;