From 2faef704b4841f735db633dbae7523985292e780 Mon Sep 17 00:00:00 2001 From: Stevie Robinson Date: Fri, 10 Nov 2023 01:00:54 +0100 Subject: [PATCH] Fixed: Replacing 'appName' translation token (cherry picked from commit 2e51b8792db0d3ec402672dc92c95f3cb886ef44) Closes #3058 Fixes #3221 --- .../Activity/Queue/RemoveQueueItemsModal.js | 2 +- frontend/src/Utilities/String/translate.ts | 20 +++++++++---------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/frontend/src/Activity/Queue/RemoveQueueItemsModal.js b/frontend/src/Activity/Queue/RemoveQueueItemsModal.js index aebee05b0..0e9f1d590 100644 --- a/frontend/src/Activity/Queue/RemoveQueueItemsModal.js +++ b/frontend/src/Activity/Queue/RemoveQueueItemsModal.js @@ -94,7 +94,7 @@ class RemoveQueueItemsModal extends Component {
- {selectedCount > 1 ? translate('RemoveSelectedItemsQueueMessageText', selectedCount) : translate('RemoveSelectedItemQueueMessageText')} + {selectedCount > 1 ? translate('RemoveSelectedItemsQueueMessageText', { selectedCount }) : translate('RemoveSelectedItemQueueMessageText')}
{ diff --git a/frontend/src/Utilities/String/translate.ts b/frontend/src/Utilities/String/translate.ts index ee8891080..8881ad0aa 100644 --- a/frontend/src/Utilities/String/translate.ts +++ b/frontend/src/Utilities/String/translate.ts @@ -25,20 +25,18 @@ export async function fetchTranslations(): Promise { export default function translate( key: string, - tokens: Record = { appName: 'Readarr' } + tokens: Record = {} ) { const translation = translations[key] || key; - if (tokens) { - // Fallback to the old behaviour for translations not yet updated to use named tokens - Object.values(tokens).forEach((value, index) => { - tokens[index] = value; - }); + tokens.appName = 'Readarr'; - return translation.replace(/\{([a-z0-9]+?)\}/gi, (match, tokenMatch) => - String(tokens[tokenMatch] ?? match) - ); - } + // Fallback to the old behaviour for translations not yet updated to use named tokens + Object.values(tokens).forEach((value, index) => { + tokens[index] = value; + }); - return translation; + return translation.replace(/\{([a-z0-9]+?)\}/gi, (match, tokenMatch) => + String(tokens[tokenMatch] ?? match) + ); }