File

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

Index

Properties

Properties

datePicker (Optional)
Type TalyDatepickerI18nConfig
fileUploader (Optional)
Type TalyFileUploaderI18nConfig
mobileStepLabel (Optional)
Type string
timeField (Optional)
Type TalyTimefieldI18nConfig
turnstileRequiredError (Optional)
Type string
import {
  ModuleWithProviders,
  NgModule,
  InjectionToken,
  Injector,
  Signal,
  signal,
  inject
} from '@angular/core';
import { I18nPlugin } from './i18n-plugin';
import {
  type FileUploaderErrorKey,
  type FileUploaderUiLabelKey
} from '../file-uploader-component-plugin/file-uploader-config.model';

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>> & {
  invalidDateFormatError?: string;
};

export const FILE_UPLOADER_LABEL_KEYS = ['deleteLabel', 'uploadedListLabel'] as const;

export type FileUploaderLabelKey = (typeof FILE_UPLOADER_LABEL_KEYS)[number];

export type TalyFileUploaderI18nConfig = Partial<Record<FileUploaderLabelKey, string>> &
  Partial<Record<FileUploaderErrorKey, string>> &
  Partial<Record<FileUploaderUiLabelKey, string>>;

export const TIMEFIELD_LABEL_KEYS = [
  'inputFieldHoursAriaLabel',
  'inputFieldMinutesAriaLabel',
  'buttonOpenTimepickerAriaLabel'
] as const;

export type TimeFieldLabelKey = (typeof TIMEFIELD_LABEL_KEYS)[number];

export type TalyTimefieldI18nConfig = Partial<Record<TimeFieldLabelKey, string>> & {
  invalidTimeFormatError?: string;
};

export interface TalyI18nConfig {
  datePicker?: TalyDatepickerI18nConfig;
  fileUploader?: TalyFileUploaderI18nConfig;
  timeField?: TalyTimefieldI18nConfig;
  turnstileRequiredError?: string;
  mobileStepLabel?: string;
}

@NgModule({
  providers: [I18nPlugin]
})
export class I18nPluginModule {
  constructor() {
    inject(I18nPlugin);
  }

  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 ""