1- import { Component , OnInit , ViewChild } from '@angular/core' ;
2- import { registerLocaleData } from '@angular/common' ;
3- import { FormsModule } from '@angular/forms' ;
1+ import { Component , CUSTOM_ELEMENTS_SCHEMA , OnInit , ViewChild } from '@angular/core' ;
2+ import { formatDate , registerLocaleData } from '@angular/common' ;
3+ import { FormsModule , ReactiveFormsModule } from '@angular/forms' ;
44
55import localeBG from '@angular/common/locales/bg' ;
66import localeEN from '@angular/common/locales/en' ;
@@ -19,13 +19,42 @@ import {
1919 IgxResourceStringsBG , IgxResourceStringsDE , IgxResourceStringsES , IgxResourceStringsFR , IgxResourceStringsIT ,
2020 IgxResourceStringsJA , IgxResourceStringsKO , IgxResourceStringsZHHANS , IgxResourceStringsZHHANT
2121} from 'igniteui-angular-i18n' ;
22- import { IResourceStrings , GridResourceStringsEN , IgxColumnComponent , IgxGridComponent , IgxSelectComponent , IgxSelectItemComponent , IgxGridToolbarComponent , IgxGridToolbarTitleComponent , IgxPaginatorComponent , changei18n } from 'igniteui-angular' ;
22+ import {
23+ IResourceStrings ,
24+ GridResourceStringsEN ,
25+ IgxColumnComponent ,
26+ IgxGridComponent ,
27+ IgxSelectComponent ,
28+ IgxSelectItemComponent ,
29+ IgxGridToolbarComponent ,
30+ IgxGridToolbarTitleComponent ,
31+ IgxPaginatorComponent ,
32+ changei18n ,
33+ IgxGridPinningActionsComponent ,
34+ IgxGridEditingActionsComponent ,
35+ IgxActionStripComponent
36+ } from 'igniteui-angular' ;
37+ import { setCurrentI18n , getI18nManager , registerI18n , ResourceStringsEN } from 'igniteui-i18n-core' ;
38+ import { ResourceStringsBG , ResourceStringsDE , ResourceStringsES , ResourceStringsFR , ResourceStringsIT , ResourceStringsJA , ResourceStringsKO , ResourceStringsZHHANS , ResourceStringsZHHANT } from 'igniteui-i18n-resources' ;
2339
2440@Component ( {
2541 selector : 'app-grid-localization' ,
2642 styleUrls : [ './grid-localization.sample.scss' ] ,
2743 templateUrl : 'grid-localization.sample.html' ,
28- imports : [ IgxGridComponent , IgxColumnComponent , IgxGridToolbarComponent , IgxGridToolbarTitleComponent , IgxSelectComponent , FormsModule , IgxSelectItemComponent , IgxPaginatorComponent ]
44+ imports : [
45+ FormsModule ,
46+ ReactiveFormsModule ,
47+ IgxGridComponent ,
48+ IgxColumnComponent ,
49+ IgxGridToolbarComponent ,
50+ IgxGridToolbarTitleComponent ,
51+ IgxSelectComponent ,
52+ IgxSelectItemComponent ,
53+ IgxPaginatorComponent ,
54+ IgxGridPinningActionsComponent ,
55+ IgxGridEditingActionsComponent ,
56+ IgxActionStripComponent
57+ ]
2958} )
3059
3160export class GridLocalizationSampleComponent implements OnInit {
@@ -37,20 +66,10 @@ export class GridLocalizationSampleComponent implements OnInit {
3766 public selectLocales = [ 'HI' , 'BG' , 'EN' , 'DE' , 'ES' , 'FR' , 'IT' , 'JA' , 'KO' , 'zh-Hans' , 'zh-Hant' ] ;
3867 public cashedLocalizationEN : IResourceStrings ;
3968 public partialCustomHindi : IResourceStrings ;
69+ public inputValue ;
4070
4171 constructor ( ) { }
4272 public ngOnInit ( ) : void {
43- registerLocaleData ( localeBG ) ;
44- registerLocaleData ( localeEN ) ;
45- registerLocaleData ( localeDE ) ;
46- registerLocaleData ( localeES ) ;
47- registerLocaleData ( localeFR ) ;
48- registerLocaleData ( localeIT ) ;
49- registerLocaleData ( localeJA ) ;
50- registerLocaleData ( localeKO ) ;
51- registerLocaleData ( localeHans ) ;
52- registerLocaleData ( localeHant ) ;
53- registerLocaleData ( localeHI ) ;
5473 this . data = DATA ;
5574 this . cashedLocalizationEN = Object . assign ( { } , GridResourceStringsEN ) ;
5675 // Creating a custom locale (HI) for specific grid strings.
@@ -78,11 +97,48 @@ export class GridLocalizationSampleComponent implements OnInit {
7897 ] ;
7998
8099 this . locale = 'EN' ;
100+
101+ // Old way by Angular
102+ // registerLocaleData(localeBG);
103+ // registerLocaleData(localeEN);
104+ // registerLocaleData(localeDE);
105+ // registerLocaleData(localeES);
106+ // registerLocaleData(localeFR);
107+ // registerLocaleData(localeIT);
108+ // registerLocaleData(localeJA);
109+ // registerLocaleData(localeKO);
110+ // registerLocaleData(localeHans);
111+ // registerLocaleData(localeHant);
112+ // registerLocaleData(localeHI);
113+
114+ // New API
115+ registerI18n ( ResourceStringsBG , 'bg' ) ;
116+ registerI18n ( ResourceStringsEN , 'en' ) ;
117+ registerI18n ( ResourceStringsDE , 'de' ) ;
118+ registerI18n ( ResourceStringsES , 'es' ) ;
119+ registerI18n ( ResourceStringsFR , 'fr' ) ;
120+ registerI18n ( ResourceStringsIT , 'it' ) ;
121+ registerI18n ( ResourceStringsJA , 'ja' ) ;
122+ registerI18n ( ResourceStringsKO , 'ko' ) ;
123+ registerI18n ( ResourceStringsZHHANS , 'zh-Hans' ) ;
124+ registerI18n ( ResourceStringsZHHANT , 'zh-Hant' ) ;
125+
81126 }
82127
83128 public updateLocale ( ) {
84129 const newLocale = this . locales . find ( x => x . type === this . locale ) . resource ;
130+ // Manual assign of resource strings.
85131 //this.grid.resourceStrings = newLocale;
86- changei18n ( newLocale ) ;
132+
133+ // Old API
134+ // changei18n(newLocale);
135+
136+ // New API
137+ setCurrentI18n ( this . locale ) ;
138+ }
139+
140+ public onButtonClick ( ) {
141+ console . log ( "Old: " + formatDate ( new Date ( "10/10/1993" ) , this . inputValue , this . locale ) ) ;
142+ console . log ( "New: " + getI18nManager ( ) . formatDateCustomFormat ( new Date ( "10/10/1993" ) , this . locale , this . inputValue ) ) ;
87143 }
88144}
0 commit comments