-
Notifications
You must be signed in to change notification settings - Fork 125
/
date-picker-i18n-example.component.ts
73 lines (58 loc) · 2.2 KB
/
date-picker-i18n-example.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { CalendarI18n } from '../../../../../../library/src/lib/calendar/i18n/calendar-i18n';
import { Component, Injectable } from '@angular/core';
import { CalendarI18nLabels } from '../../../../../../library/src/lib/calendar/i18n/calendar-i18n-labels';
const localized_values = {
'fr': {
weekdays: ['Di', 'Lu', 'Ma', 'Me', 'Je', 'Ve', 'Sa'],
months: ['Jan', 'Fév', 'Mar', 'Avr', 'Mai', 'Juin', 'Juil', 'Aou', 'Sep', 'Oct', 'Nov', 'Déc'],
fullMonths: ['Janvier', 'Février', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet',
'Aout', 'Septembre', 'Octobre', 'Novembre', 'Décembre'],
}
};
@Injectable()
export class CustomCalendarI18n extends CalendarI18n {
// You could also define a custom service and inject it here
language: string = 'fr';
getDayAriaLabel(date: Date): string {
return date.getDate() + ' ' + localized_values[this.language].fullMonths[date.getMonth()] + ' ' + date.getFullYear();
}
getAllFullMonthNames(): string[] {
return localized_values[this.language].fullMonths;
}
getAllShortMonthNames(): string[] {
return localized_values[this.language].months;
}
getAllShortWeekdays(): string[] {
return localized_values[this.language].weekdays;
}
}
// Aria labels i18n
@Injectable()
export class CustomI18nLabels extends CalendarI18nLabels {
yearSelectionLabel: string = 'Sélection de l\'année';
previousYearLabel: string = 'Année précédente';
nextYearLabel: string = 'Année suivante';
monthSelectionLabel: string = 'Sélection du mois';
previousMonthLabel: string = 'Mois précédent';
nextMonthLabel: string = 'Mois suivant';
}
@Component({
selector: 'fd-datepicker-i18n-example',
template: `<fd-date-picker [(ngModel)]="selectedDay" [placement]="'top-end'"></fd-date-picker>`,
// Note that this can be provided in the root of your application.
providers: [
{
provide: CalendarI18n,
useClass: CustomCalendarI18n
},
{
provide: CalendarI18nLabels,
useClass: CustomI18nLabels
}
]
})
export class DatePickerI18nExampleComponent {
selectedDay = {
date: new Date()
};
}