Browse Source

Add TimepickerI18nAdapter for ng-bootstrap timepicker

Introduces TimepickerI18nAdapter to provide localized AM/PM labels for NgbTimepickerI18n. Updates providers and index exports to register and expose the new adapter.
pull/24194/head
Fahri Gedik 3 months ago
parent
commit
cf2065e166
  1. 1
      npm/ng-packs/packages/theme-shared/src/lib/adapters/index.ts
  2. 24
      npm/ng-packs/packages/theme-shared/src/lib/adapters/timepicker-i18n.adapter.ts
  3. 8
      npm/ng-packs/packages/theme-shared/src/lib/providers/ng-bootstrap-config.provider.ts

1
npm/ng-packs/packages/theme-shared/src/lib/adapters/index.ts

@ -2,3 +2,4 @@ export * from './date-time.adapter';
export * from './date.adapter';
export * from './datepicker-i18n.adapter';
export * from './time.adapter';
export * from './timepicker-i18n.adapter';

24
npm/ng-packs/packages/theme-shared/src/lib/adapters/timepicker-i18n.adapter.ts

@ -0,0 +1,24 @@
import { formatDate } from '@angular/common';
import { inject, Injectable, LOCALE_ID } from '@angular/core';
import { NgbTimepickerI18n } from '@ng-bootstrap/ng-bootstrap';
import { ConfigStateService } from '@abp/ng.core';
@Injectable()
export class TimepickerI18nAdapter extends NgbTimepickerI18n {
private configState = inject(ConfigStateService, { optional: true });
private defaultLocale = inject(LOCALE_ID);
private get locale(): string {
return this.configState?.getDeep('localization.currentCulture.cultureName') || this.defaultLocale;
}
getMorningPeriod(): string {
const date = new Date(2000, 0, 1, 10, 0, 0);
return formatDate(date, 'a', this.locale);
}
getAfternoonPeriod(): string {
const date = new Date(2000, 0, 1, 22, 0, 0);
return formatDate(date, 'a', this.locale);
}
}

8
npm/ng-packs/packages/theme-shared/src/lib/providers/ng-bootstrap-config.provider.ts

@ -1,12 +1,16 @@
import { inject, provideAppInitializer } from '@angular/core';
import { NgbDatepickerI18n, NgbInputDatepickerConfig, NgbTypeaheadConfig } from '@ng-bootstrap/ng-bootstrap';
import { DatepickerI18nAdapter } from '../adapters';
import { NgbDatepickerI18n, NgbInputDatepickerConfig, NgbTypeaheadConfig, NgbTimepickerI18n } from '@ng-bootstrap/ng-bootstrap';
import { DatepickerI18nAdapter, TimepickerI18nAdapter } from '../adapters';
export const NG_BOOTSTRAP_CONFIG_PROVIDERS = [
{
provide: NgbDatepickerI18n,
useClass: DatepickerI18nAdapter,
},
{
provide: NgbTimepickerI18n,
useClass: TimepickerI18nAdapter,
},
provideAppInitializer(() => {
configureNgBootstrap();
}),

Loading…
Cancel
Save