1
- import { Input , Output , EventEmitter , Directive } from '@angular/core' ;
1
+ import { Input , Output , EventEmitter , Directive , Inject , LOCALE_ID } from '@angular/core' ;
2
2
import { WEEKDAYS , Calendar , isDateInRanges , IFormattingOptions , IFormattingViews } from './calendar' ;
3
3
import { ControlValueAccessor } from '@angular/forms' ;
4
4
import { DateRangeDescriptor } from '../core/dates' ;
@@ -163,7 +163,7 @@ export class IgxCalendarBaseDirective implements ControlValueAccessor {
163
163
/**
164
164
* @hidden
165
165
*/
166
- private _locale = 'en' ;
166
+ private _locale ;
167
167
168
168
/**
169
169
* @hidden
@@ -240,6 +240,8 @@ export class IgxCalendarBaseDirective implements ControlValueAccessor {
240
240
* Can be assigned to a numeric value or to `WEEKDAYS` enum value.
241
241
*/
242
242
public set weekStart ( value : WEEKDAYS | number ) {
243
+ this . _weekStart = value ;
244
+
243
245
this . calendarModel . firstWeekDay = value ;
244
246
}
245
247
@@ -252,16 +254,25 @@ export class IgxCalendarBaseDirective implements ControlValueAccessor {
252
254
return this . _locale ;
253
255
}
254
256
257
+ private _weekStart : number | WEEKDAYS ;
258
+
255
259
/**
256
260
* Sets the `locale` of the calendar.
257
261
* Expects a valid BCP 47 language tag.
258
262
* Default value is `"en"`.
259
263
*/
260
264
public set locale ( value : string ) {
261
265
this . _locale = value ;
262
- if ( ! this . weekStart ) {
266
+ try {
267
+ getLocaleFirstDayOfWeek ( this . _locale ) ;
268
+ } catch ( e ) {
269
+ this . _locale = this . _localeId ;
270
+ }
271
+
272
+ if ( this . _weekStart === undefined ) {
263
273
this . calendarModel . firstWeekDay = getLocaleFirstDayOfWeek ( this . _locale ) ;
264
274
}
275
+
265
276
this . initFormatters ( ) ;
266
277
}
267
278
@@ -440,8 +451,9 @@ export class IgxCalendarBaseDirective implements ControlValueAccessor {
440
451
/**
441
452
* @hidden
442
453
*/
443
- constructor ( protected platform : PlatformUtil ) {
454
+ constructor ( protected platform : PlatformUtil , @ Inject ( LOCALE_ID ) protected _localeId : any ) {
444
455
this . calendarModel = new Calendar ( ) ;
456
+ this . locale = _localeId ;
445
457
446
458
this . viewDate = this . viewDate ? this . viewDate : new Date ( ) ;
447
459
0 commit comments