From a06d88eddf468c2f8b8b942d8bfa73c810441ef9 Mon Sep 17 00:00:00 2001 From: Johannes Millan Date: Sun, 8 Jun 2025 17:33:38 +0200 Subject: [PATCH] fix(i18n): avoid error "Parameter 'key' required" #4133 --- .../formly-translate-extension.ts | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/app/ui/formly-translate-extension/formly-translate-extension.ts b/src/app/ui/formly-translate-extension/formly-translate-extension.ts index f03989b06..c8312733d 100644 --- a/src/app/ui/formly-translate-extension/formly-translate-extension.ts +++ b/src/app/ui/formly-translate-extension/formly-translate-extension.ts @@ -12,9 +12,21 @@ export class TranslateExtension { const to = field.templateOptions || {}; if (Array.isArray(to.options)) { const options = to.options; - to.options = this.translate - .stream(options.map((o) => o.label)) - .pipe(map((labels) => options.map((o) => ({ ...o, label: labels[o.label] })))); + // Filter out options without valid labels to prevent "Parameter key required" error + const validOptions = options.filter((o) => o && o.label); + if (validOptions.length > 0) { + to.options = this.translate.stream(validOptions.map((o) => o.label)).pipe( + map((labels) => + options.map((o) => { + // Skip translation for items with invalid labels + if (!o || !o.label) { + return o; + } + return { ...o, label: labels[o.label] }; + }), + ), + ); + } } const validators = field.validators || {}; @@ -27,11 +39,13 @@ export class TranslateExtension { field.expressionProperties = { ...(field.expressionProperties || {}), - ...(to.label ? { 'templateOptions.label': this.translate.stream(to.label) } : {}), - ...(to.description + ...(typeof to.label === 'string' + ? { 'templateOptions.label': this.translate.stream(to.label) } + : {}), + ...(typeof to.description === 'string' ? { 'templateOptions.description': this.translate.stream(to.description) } : {}), - ...(to.placeholder + ...(typeof to.placeholder === 'string' ? { 'templateOptions.placeholder': this.translate.stream(to.placeholder) } : {}), };