File

libs/core-forms/src/lib/i18n-plugin/i18n-plugin.module.ts

Index

Properties

Properties

datePicker (Optional)
Type TalyDatepickerI18nConfig
import { NxDatepickerIntl } from '@allianz/ng-aquila/datefield';
import {
  ModuleWithProviders,
  NgModule,
  InjectionToken,
  Injector,
  Signal,
  signal
} from '@angular/core';
import { I18nPlugin } from './i18n-plugin';

export const I18N_PLUGIN_OPTIONS = new InjectionToken<Signal<TalyI18nConfig>>(
  'I18N_PLUGIN_OPTIONS'
);

export const DEFAULT_OPTIONS: TalyI18nConfig = {};

export const DATEPICKER_LABEL_KEYS = [
  'openCalendarLabel',
  'closeIconLabel',
  'prevMonthLabel',
  'nextMonthLabel',
  'prevYearLabel',
  'nextYearLabel',
  'prevMultiYearLabel',
  'nextMultiYearLabel',
  'switchToMonthViewLabel',
  'switchToMultiYearViewLabel'
] as const;

export type DatePickerLabelKey = (typeof DATEPICKER_LABEL_KEYS)[number];

export type TalyDatepickerI18nConfig = Partial<Record<DatePickerLabelKey, string>>;

export interface TalyI18nConfig {
  datePicker?: TalyDatepickerI18nConfig;
}

@NgModule({
  providers: [
    {
      provide: NxDatepickerIntl,
      useClass: I18nPlugin
    }
  ]
})
export class I18nPluginModule {
  static forRoot(
    optionsFactory?: (injector: Injector) => Signal<TalyI18nConfig | undefined>
  ): ModuleWithProviders<I18nPluginModule> {
    const defaultFactory = () => signal<TalyI18nConfig>(DEFAULT_OPTIONS);
    return {
      ngModule: I18nPluginModule,
      providers: [
        {
          provide: I18N_PLUGIN_OPTIONS,
          useFactory: optionsFactory || defaultFactory,
          deps: [Injector]
        }
      ]
    };
  }
}

results matching ""

    No results matching ""