diff --git a/src/lib/inputs/details-radio/details-radio.component.ts b/src/lib/inputs/details-radio/details-radio.component.ts index e1419e8..2e8408a 100644 --- a/src/lib/inputs/details-radio/details-radio.component.ts +++ b/src/lib/inputs/details-radio/details-radio.component.ts @@ -1,14 +1,21 @@ -import { Component, EventEmitter, Input, Output } from '@angular/core'; +import { Component, EventEmitter, inject, Input, OnChanges, Output, SimpleChanges } from '@angular/core'; import { DetailsRadioOption } from './details-radio-option'; import { FormsModule, NG_VALIDATORS, NG_VALUE_ACCESSOR, ReactiveFormsModule } from '@angular/forms'; import { FormFieldComponent } from '../form-field/form-field-component.directive'; import { NgClass, NgForOf, NgIf } from '@angular/common'; import { RoundCheckboxComponent } from '../round-checkbox/round-checkbox.component'; -import { TranslateModule } from '@ngx-translate/core'; +import { TranslateModule, TranslateService } from '@ngx-translate/core'; import { MatIconModule } from '@angular/material/icon'; import { MatCheckboxModule } from '@angular/material/checkbox'; import { MatTooltipModule } from '@angular/material/tooltip'; import { ReplaceNbspPipe } from '../../pipes/replace-nbsp.pipe'; +import { removeActionDescriptorTranslations } from '../../../../../../apps/red-ui/src/app/translations/redact-text-translations'; +import { List } from '../../utils'; + +export const removeActionDescriptorTranslationsPaths: List = [ + removeActionDescriptorTranslations.redact, + removeActionDescriptorTranslations.recommend, +]; @Component({ selector: 'iqser-details-radio [options]', @@ -41,16 +48,32 @@ import { ReplaceNbspPipe } from '../../pipes/replace-nbsp.pipe'; ReplaceNbspPipe, ], }) -export class DetailsRadioComponent extends FormFieldComponent> { +export class DetailsRadioComponent extends FormFieldComponent> implements OnChanges { @Input() options: DetailsRadioOption[] = []; @Input() displayInRow = false; @Output() readonly extraOptionChanged: EventEmitter> = new EventEmitter(); + readonly #translateService = inject(TranslateService); constructor() { super(); } + ngOnChanges(changes: SimpleChanges) { + if (!changes['options']) return; + this.options = this.options.map(option => { + const type = option.descriptionParams?.['type']; + if (!type) return option; + return { + ...option, + descriptionParams: { + ...option.descriptionParams, + type: removeActionDescriptorTranslationsPaths.includes(type) ? this.#translateService.instant(type) : type, + }, + }; + }); + } + toggleOption(option: DetailsRadioOption): void { if (option.value !== this._value?.value && !option.disabled) { this.markAsTouched();