From 3f7121c6abb381f5d1645da70dad099d56a5b0d9 Mon Sep 17 00:00:00 2001 From: Maicol Battistini Date: Thu, 20 Jan 2022 15:53:46 +0100 Subject: [PATCH] =?UTF-8?q?impr(i18n):=20=F0=9F=8C=90=20=F0=9F=9A=B8=20Mig?= =?UTF-8?q?liorata=20funzione=20di=20traduzione?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Viene sempre restituita una stringa. Rimossi i parametri che forzavano il return della traduzione come stringa --- resources/js/utils.ts | 32 +++++++------------------------- 1 file changed, 7 insertions(+), 25 deletions(-) diff --git a/resources/js/utils.ts b/resources/js/utils.ts index 59474fc35..66d098833 100644 --- a/resources/js/utils.ts +++ b/resources/js/utils.ts @@ -128,39 +128,21 @@ type ReplaceObject = Record; * @protected */ // eslint-disable-next-line @typescript-eslint/naming-convention -export function __( - key: string, - replace: ReplaceObject | boolean = {}, - returnAsString: boolean = false -): string { +export function __(key: string, replace: ReplaceObject = {}): string { let translation = key; - // noinspection JSUnresolvedVariable if (translations && translations[key]) { translation = translations[key]; } - // Returns translation as string (no parameters replacement) - if (replace === true - || (typeof replace === 'object' && !containsHTML(translation)) - ) { - return translation; - } - - for (const k of Object.keys(replace)) { - const replacement = (replace as ReplaceObject)[k]; - + for (const [parameter, replacement] of Object.entries(replace)) { // `'attrs' in replacement` checks if `replacement` is a Mithril Vnode. - translation = translation.replace( - `:${k}`, - typeof replacement === 'object' && 'attrs' in replacement - ? render(replacement) - : replacement as string - ); - } + const isVnode = typeof replacement === 'object' && 'attrs' in replacement; - if (returnAsString || !containsHTML(translation)) { - return translation; + translation = translation.replace( + `:${parameter}`, + isVnode ? render(replacement) : replacement as string + ); } return translation;