fix(i18n): avoid error "Parameter 'key' required" #4133

This commit is contained in:
Johannes Millan 2025-06-08 17:33:38 +02:00
parent 202bb3652a
commit a06d88eddf

View file

@ -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) }
: {}),
};