From ee6a2be8dc89c29da14145118fbf4803bc2047e7 Mon Sep 17 00:00:00 2001 From: Nassim Tabchiche Date: Tue, 22 Oct 2024 12:59:10 +0200 Subject: [PATCH] Fix unsafeTranslate function This first tests key, then toCamelCase(key) --- frontend/src/lib/utils/i18n.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/frontend/src/lib/utils/i18n.ts b/frontend/src/lib/utils/i18n.ts index 7022e969f..ad8357744 100644 --- a/frontend/src/lib/utils/i18n.ts +++ b/frontend/src/lib/utils/i18n.ts @@ -8,10 +8,12 @@ import { toCamelCase } from '$lib/utils/locales'; * @param options The options to pass to the translation function. */ export function unsafeTranslate(key: string, params = {}, options = {}): string | undefined { - key = toCamelCase(key); if (Object.hasOwn(m, key)) { return m[key](params, options); } + if (Object.hasOwn(m, toCamelCase(key))) { + return m[toCamelCase(key)](params, options); + } } /** @@ -21,5 +23,5 @@ export function unsafeTranslate(key: string, params = {}, options = {}): string * @param options The options to pass to the translation function. */ export function safeTranslate(key: string, params = {}, options = {}): string { - return unsafeTranslate(key) || key; + return unsafeTranslate(key, params, options) || key; }