Fixed: Replacing 'appName' translation token

(cherry picked from commit 2e51b8792db0d3ec402672dc92c95f3cb886ef44)

Closes #3058
Fixes #3221
pull/3223/head v0.3.16.2387
Stevie Robinson 1 year ago committed by Bogdan
parent a566c3e21f
commit 2faef704b4

@ -94,7 +94,7 @@ class RemoveQueueItemsModal extends Component {
<ModalBody> <ModalBody>
<div className={styles.message}> <div className={styles.message}>
{selectedCount > 1 ? translate('RemoveSelectedItemsQueueMessageText', selectedCount) : translate('RemoveSelectedItemQueueMessageText')} {selectedCount > 1 ? translate('RemoveSelectedItemsQueueMessageText', { selectedCount }) : translate('RemoveSelectedItemQueueMessageText')}
</div> </div>
{ {

@ -25,20 +25,18 @@ export async function fetchTranslations(): Promise<boolean> {
export default function translate( export default function translate(
key: string, key: string,
tokens: Record<string, string | number | boolean> = { appName: 'Readarr' } tokens: Record<string, string | number | boolean> = {}
) { ) {
const translation = translations[key] || key; const translation = translations[key] || key;
if (tokens) { tokens.appName = 'Readarr';
// 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.replace(/\{([a-z0-9]+?)\}/gi, (match, tokenMatch) => // Fallback to the old behaviour for translations not yet updated to use named tokens
String(tokens[tokenMatch] ?? match) Object.values(tokens).forEach((value, index) => {
); tokens[index] = value;
} });
return translation; return translation.replace(/\{([a-z0-9]+?)\}/gi, (match, tokenMatch) =>
String(tokens[tokenMatch] ?? match)
);
} }

Loading…
Cancel
Save