From 76a8e000a361d334b03abc00b31b4215c773a947 Mon Sep 17 00:00:00 2001 From: Johann150 Date: Tue, 27 Dec 2022 21:47:34 +0100 Subject: [PATCH] client: only catch erroneous key errors in i18n.ts --- packages/client/src/i18n.ts | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/packages/client/src/i18n.ts b/packages/client/src/i18n.ts index b50cd7290..823900677 100644 --- a/packages/client/src/i18n.ts +++ b/packages/client/src/i18n.ts @@ -20,23 +20,24 @@ class I18n> { // If a pattern is present in the string but not provided in args, it will not be replaced. // If `args` is not provided, no interpolation is performed. public t(key: string, args?: Record): string { + let str; try { // Resolve dot-delimited names as properties of objects. - let str = key.split('.').reduce((o, i) => o[i], this.ts) as unknown as string; - - // Perform string interpolation. - if (args) { - for (const [k, v] of Object.entries(args)) { - str = str.replace(`{${k}}`, v.toString()); - } - } - - return str; + str = key.split('.').reduce((o, i) => o[i], this.ts) as unknown as string; } catch (err) { // This should normally not happen because of the English language fallback strings, see comment for ts member. console.warn(`missing localization '${key}'`); return key; } + + // Perform string interpolation. + if (args) { + for (const [k, v] of Object.entries(args)) { + str = str.replace(`{${k}}`, v.toString()); + } + } + + return str; } }