use translation service to determine placeholder values of date picker (#2827)

* use translation service to determine placeholder values

* added translation of date-picker placeholder values

* added German translations of date-picker placeholder values

* fix lint warning: added missing comma

* fix lint warning: removed trailing spaces

* fixed broken tests

* fixed lint warning

* try to mock TranslateService correctly

* remove TranslateService mock

* removed imports

* fixed lint warnings

* fixed lint warnings

* fixed lint warning

* fixed lint warning

* fixed lint error

* fixed lint errors

* removed TestComponent

* added imports

* removed declarations

* fixed lint error

* fix lint error (invalid sorting)

* finally fixing lint error

* use translation pipe directly in template

* move translation of placeholders into HTML template

* remove TranslateService dependency
This commit is contained in:
Sascha Szott
2025-02-06 22:05:36 +01:00
committed by Tim Donohue
parent 59e6c4abf5
commit c6deb2271d
5 changed files with 26 additions and 8 deletions

View File

@@ -14,7 +14,7 @@
[(ngModel)]="initialYear" [(ngModel)]="initialYear"
[value]="year" [value]="year"
[invalid]="showErrorMessages" [invalid]="showErrorMessages"
[placeholder]='yearPlaceholder' [placeholder]="'form.date-picker.placeholder.year' | translate"
(blur)="onBlur($event)" (blur)="onBlur($event)"
(change)="onChange($event)" (change)="onChange($event)"
(focus)="onFocus($event)" (focus)="onFocus($event)"
@@ -29,7 +29,7 @@
[size]="6" [size]="6"
[(ngModel)]="initialMonth" [(ngModel)]="initialMonth"
[value]="month" [value]="month"
[placeholder]="monthPlaceholder" [placeholder]="'form.date-picker.placeholder.month' | translate"
[disabled]="!year || model.disabled" [disabled]="!year || model.disabled"
(blur)="onBlur($event)" (blur)="onBlur($event)"
(change)="onChange($event)" (change)="onChange($event)"
@@ -45,7 +45,7 @@
[size]="2" [size]="2"
[(ngModel)]="initialDay" [(ngModel)]="initialDay"
[value]="day" [value]="day"
[placeholder]="dayPlaceholder" [placeholder]="'form.date-picker.placeholder.day' | translate"
[disabled]="!month || model.disabled" [disabled]="!month || model.disabled"
(blur)="onBlur($event)" (blur)="onBlur($event)"
(change)="onChange($event)" (change)="onChange($event)"

View File

@@ -24,7 +24,10 @@ import {
DynamicFormLayoutService, DynamicFormLayoutService,
DynamicFormValidationService, DynamicFormValidationService,
} from '@ng-dynamic-forms/core'; } from '@ng-dynamic-forms/core';
import { TranslateService } from '@ngx-translate/core'; import {
TranslateModule,
TranslateService,
} from '@ngx-translate/core';
import { of as observableOf } from 'rxjs'; import { of as observableOf } from 'rxjs';
import { import {
@@ -80,6 +83,7 @@ describe('DsDatePickerComponent test suite', () => {
NgbModule, NgbModule,
DsDatePickerComponent, DsDatePickerComponent,
TestComponent, TestComponent,
TranslateModule.forRoot(),
], ],
providers: [ providers: [
ChangeDetectorRef, ChangeDetectorRef,

View File

@@ -22,6 +22,7 @@ import {
DynamicFormLayoutService, DynamicFormLayoutService,
DynamicFormValidationService, DynamicFormValidationService,
} from '@ng-dynamic-forms/core'; } from '@ng-dynamic-forms/core';
import { TranslateModule } from '@ngx-translate/core';
import isEqual from 'lodash/isEqual'; import isEqual from 'lodash/isEqual';
import { BtnDisabledDirective } from '../../../../../btn-disabled.directive'; import { BtnDisabledDirective } from '../../../../../btn-disabled.directive';
@@ -42,6 +43,7 @@ export const DS_DATE_PICKER_SEPARATOR = '-';
NgIf, NgIf,
NumberPickerComponent, NumberPickerComponent,
FormsModule, FormsModule,
TranslateModule,
BtnDisabledDirective, BtnDisabledDirective,
], ],
standalone: true, standalone: true,
@@ -74,10 +76,6 @@ export class DsDatePickerComponent extends DynamicFormControlComponent implement
minDay = 1; minDay = 1;
maxDay = 31; maxDay = 31;
yearPlaceholder = 'year';
monthPlaceholder = 'month';
dayPlaceholder = 'day';
disabledMonth = true; disabledMonth = true;
disabledDay = true; disabledDay = true;

View File

@@ -5992,4 +5992,14 @@
// "workspace-item.delete.notification.error.content": "The workspace item could not be deleted", // "workspace-item.delete.notification.error.content": "The workspace item could not be deleted",
"workspace-item.delete.notification.error.content": "Das Workspace-Item konnte nicht gelöscht werden.", "workspace-item.delete.notification.error.content": "Das Workspace-Item konnte nicht gelöscht werden.",
// "form.date-picker.placeholder.year": "Year",
"form.date-picker.placeholder.year": "Jahr",
// "form.date-picker.placeholder.month": "Month",
"form.date-picker.placeholder.month": "Monat",
// "form.date-picker.placeholder.day": "Day",
"form.date-picker.placeholder.day": "Tag",
} }

View File

@@ -6764,6 +6764,12 @@
"search.filters.filter.notifyEndorsement.label": "Search Notify Endorsement", "search.filters.filter.notifyEndorsement.label": "Search Notify Endorsement",
"form.date-picker.placeholder.year": "Year",
"form.date-picker.placeholder.month": "Month",
"form.date-picker.placeholder.day": "Day",
"item.page.cc.license.title": "Creative Commons license", "item.page.cc.license.title": "Creative Commons license",
"item.page.cc.license.disclaimer": "Except where otherwised noted, this item's license is described as", "item.page.cc.license.disclaimer": "Except where otherwised noted, this item's license is described as",