@hug/ngx-g11n
Version:
Angular helpers for internationalizing and localizing your application
36 lines (32 loc) • 1.26 kB
JavaScript
import { LOCALE_ID, APP_INITIALIZER } from '@angular/core';
import { MAT_DATE_FORMATS, MAT_DATE_LOCALE, DateAdapter } from '@angular/material/core';
import { MAT_DATE_FNS_FORMATS, DateFnsAdapter } from '@angular/material-date-fns-adapter';
import { LOCALES } from '@hug/ngx-g11n/internal';
import { setDefaultOptions } from 'date-fns';
const matDateFnsAdapter = () => [
{ provide: MAT_DATE_FORMATS, useValue: MAT_DATE_FNS_FORMATS },
{ provide: DateAdapter, useClass: DateFnsAdapter, deps: [MAT_DATE_LOCALE] },
{
// eslint-disable-next-line @typescript-eslint/no-deprecated
provide: APP_INITIALIZER,
useFactory: (localeId, locales, dateAdapter) => async () => {
if (localeId in locales && locales[localeId].datefns) {
const locale = (await locales[localeId].datefns()).default;
dateAdapter.setLocale(locale);
setDefaultOptions({ locale });
}
},
deps: [LOCALE_ID, LOCALES, DateAdapter],
multi: true
}
];
const withDateFnsMaterial = () => ({
providers: [
matDateFnsAdapter()
]
});
/**
* Generated bundle index. Do not edit.
*/
export { withDateFnsMaterial };
//# sourceMappingURL=hug-ngx-g11n-material.mjs.map