Skip to content

Commit e2738a5

Browse files
committed
feat(demos): Add locale to properties panel and remove root locale register.
1 parent cf11f71 commit e2738a5

File tree

5 files changed

+28
-15
lines changed

5 files changed

+28
-15
lines changed

src/app/date-picker/date-picker.sample.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,13 @@ export class DatePickerSampleComponent {
9393
);
9494

9595
public panelConfig: PropertyPanelConfig = {
96+
locale: {
97+
control: {
98+
type: 'locale',
99+
options: ['HI', 'BG', 'EN', 'DE', 'ES', 'FR', 'IT', 'JA', 'KO', 'zh-Hans', 'zh-Hant'],
100+
defaultValue: 'EN',
101+
}
102+
},
96103
size: {
97104
control: {
98105
type: 'button-group',

src/app/properties-panel/properties-panel.component.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ <h5 class="properties-panel__title">Properties Panel</h5>
88
</label>
99
}
1010

11+
@if (getControlType(key) === 'locale') {
12+
<igx-select (selectionChanging)="updateLocale($event)" [placeholder]="config[key]?.control?.defaultValue ?? ''">
13+
@for (locale of config[key]?.control.options; track locale) {
14+
<igx-select-item [value]="locale">
15+
{{ locale }}
16+
</igx-select-item>
17+
}
18+
</igx-select>
19+
}
20+
1121
<!-- Text Input -->
1222
@if (getControlType(key) === 'text') {
1323
<igx-input-group type="border">

src/app/properties-panel/properties-panel.component.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
inject,
77
} from '@angular/core';
88
import { CommonModule } from '@angular/common';
9-
import { FormGroup, FormControl, ReactiveFormsModule } from '@angular/forms';
9+
import { FormGroup, FormControl, ReactiveFormsModule, FormsModule } from '@angular/forms';
1010
import {
1111
PropertyChangeService,
1212
PropertyPanelConfig,
@@ -25,15 +25,18 @@ import {
2525
IgxSelectItemComponent,
2626
IgxDatePickerComponent,
2727
IgxTimePickerComponent,
28-
IgxDateTimeEditorModule
28+
IgxDateTimeEditorModule,
29+
ISelectionEventArgs
2930
} from 'igniteui-angular';
31+
import { setCurrentI18n } from 'igniteui-i18n-core';
3032

3133
@Component({
3234
selector: 'app-properties-panel',
3335
standalone: true,
3436
templateUrl: './properties-panel.component.html',
3537
styleUrl: './properties-panel.component.scss',
3638
imports: [
39+
FormsModule,
3740
ReactiveFormsModule,
3841
CommonModule,
3942
IgxButtonDirective,
@@ -131,4 +134,8 @@ export class PropertiesPanelComponent {
131134
? labels
132135
: options.map((option) => option.label || option.toString());
133136
}
137+
138+
protected updateLocale(event: ISelectionEventArgs) {
139+
setCurrentI18n(event.newSelection.value);
140+
}
134141
}

src/app/properties-panel/property-change.service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ export type ControlType =
1313
'text' |
1414
'date' |
1515
'time' |
16-
'date-time';
16+
'date-time' |
17+
'locale';
1718

1819
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
1920
export type PropertyPanelConfig = {

src/main.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,5 @@
1-
import { registerLocaleData } from '@angular/common';
2-
import localeFr from '@angular/common/locales/fr';
3-
import localeDe from '@angular/common/locales/de';
4-
import localeJa from '@angular/common/locales/ja';
5-
import localeBb from '@angular/common/locales/bg';
6-
import localeZh from '@angular/common/locales/zh';
71
import { AppComponent } from './app/app.component';
82
import { bootstrapApplication } from '@angular/platform-browser';
93
import { appConfig } from './app/app.config';
104

11-
registerLocaleData(localeFr);
12-
registerLocaleData(localeDe);
13-
registerLocaleData(localeJa);
14-
registerLocaleData(localeBb);
15-
registerLocaleData(localeZh);
16-
175
bootstrapApplication(AppComponent, appConfig).catch(err => console.log(err));

0 commit comments

Comments
 (0)