Skip to content

Commit 799cf7c

Browse files
authored
fix(material/datepicker): add i18n strings (#25024)
Add i18n strings for "Start Date" and "End Date". Add `formatYearRangeLabel` to format a year of dates in a screen reader friendly way (e.g. "2019 to 2020"). The existing method, `formatYearRange`, uses a dash character which does not read well on screen readers. These three new strings are not used in this commit. They will be used in future commits as aria labels and descriptions to fix accessibility bugs.
1 parent d23c6c8 commit 799cf7c

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

src/material/datepicker/datepicker-intl.ts

+23-12
Original file line numberDiff line numberDiff line change
@@ -19,40 +19,51 @@ export class MatDatepickerIntl {
1919
readonly changes: Subject<void> = new Subject<void>();
2020

2121
/** A label for the calendar popup (used by screen readers). */
22-
calendarLabel: string = 'Calendar';
22+
calendarLabel = 'Calendar';
2323

2424
/** A label for the button used to open the calendar popup (used by screen readers). */
25-
openCalendarLabel: string = 'Open calendar';
25+
openCalendarLabel = 'Open calendar';
2626

2727
/** Label for the button used to close the calendar popup. */
28-
closeCalendarLabel: string = 'Close calendar';
28+
closeCalendarLabel = 'Close calendar';
2929

3030
/** A label for the previous month button (used by screen readers). */
31-
prevMonthLabel: string = 'Previous month';
31+
prevMonthLabel = 'Previous month';
3232

3333
/** A label for the next month button (used by screen readers). */
34-
nextMonthLabel: string = 'Next month';
34+
nextMonthLabel = 'Next month';
3535

3636
/** A label for the previous year button (used by screen readers). */
37-
prevYearLabel: string = 'Previous year';
37+
prevYearLabel = 'Previous year';
3838

3939
/** A label for the next year button (used by screen readers). */
40-
nextYearLabel: string = 'Next year';
40+
nextYearLabel = 'Next year';
4141

4242
/** A label for the previous multi-year button (used by screen readers). */
43-
prevMultiYearLabel: string = 'Previous 24 years';
43+
prevMultiYearLabel = 'Previous 24 years';
4444

4545
/** A label for the next multi-year button (used by screen readers). */
46-
nextMultiYearLabel: string = 'Next 24 years';
46+
nextMultiYearLabel = 'Next 24 years';
4747

4848
/** A label for the 'switch to month view' button (used by screen readers). */
49-
switchToMonthViewLabel: string = 'Choose date';
49+
switchToMonthViewLabel = 'Choose date';
5050

5151
/** A label for the 'switch to year view' button (used by screen readers). */
52-
switchToMultiYearViewLabel: string = 'Choose month and year';
52+
switchToMultiYearViewLabel = 'Choose month and year';
5353

54-
/** Formats a range of years. */
54+
/** A label for the first date of a range of dates (used by screen readers). */
55+
startDateLabel = 'Start date';
56+
57+
/** A label for the last date of a range of dates (used by screen readers). */
58+
endDateLabel = 'End date';
59+
60+
/** Formats a range of years (used for visuals). */
5561
formatYearRange(start: string, end: string): string {
5662
return `${start} \u2013 ${end}`;
5763
}
64+
65+
/** Formats a label for a range of years (used by screen readers). */
66+
formatYearRangeLabel(start: string, end: string): string {
67+
return `${start} to ${end}`;
68+
}
5869
}

tools/public_api_guard/material/datepicker.md

+3
Original file line numberDiff line numberDiff line change
@@ -525,14 +525,17 @@ export class MatDatepickerIntl {
525525
calendarLabel: string;
526526
readonly changes: Subject<void>;
527527
closeCalendarLabel: string;
528+
endDateLabel: string;
528529
formatYearRange(start: string, end: string): string;
530+
formatYearRangeLabel(start: string, end: string): string;
529531
nextMonthLabel: string;
530532
nextMultiYearLabel: string;
531533
nextYearLabel: string;
532534
openCalendarLabel: string;
533535
prevMonthLabel: string;
534536
prevMultiYearLabel: string;
535537
prevYearLabel: string;
538+
startDateLabel: string;
536539
switchToMonthViewLabel: string;
537540
switchToMultiYearViewLabel: string;
538541
// (undocumented)

0 commit comments

Comments
 (0)