All files / app/core/providers/locale locale.provider.ts

100% Statements 23/23
100% Branches 2/2
100% Functions 4/4
100% Lines 21/21

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 457x 7x 7x 7x 7x 7x 7x     7x 7x   7x 7x 7x   7x 7x 7x   7x   7x 30x                 18x           7x 30x          
import { importProvidersFrom, LOCALE_ID } from '@angular/core';
import { HttpBackend, HttpClient } from '@angular/common/http';
import { MAT_DATE_LOCALE } from '@angular/material/core';
import { MAT_MOMENT_DATE_FORMATS, provideMomentDateAdapter } from '@angular/material-moment-adapter';
import {TranslateModule, TranslateLoader} from "@ngx-translate/core";
import { TranslateHttpLoader } from '@ngx-translate/http-loader';
import { registerLocaleData } from '@angular/common';
 
// EN Locale
import en from '@angular/common/locales/en';
registerLocaleData(en);
// ES Locale
import 'moment/locale/es';
import es from '@angular/common/locales/es';
registerLocaleData(es);
 
export enum LOCALES {
  EN = 'en-US',
  ES = 'es-ES'
}
export const DEFAULT_LOCALE = LOCALES.EN;
 
export const provideLocales = () => {
  return [
    {provide: LOCALE_ID, useValue: DEFAULT_LOCALE},
    {provide: MAT_DATE_LOCALE, useValue: DEFAULT_LOCALE},
    provideMomentDateAdapter(MAT_MOMENT_DATE_FORMATS, {useUtc: true}),
    importProvidersFrom([TranslateModule.forRoot({
      defaultLanguage: DEFAULT_LOCALE,
      loader: {
        provide: TranslateLoader,
        deps: [HttpBackend],
        useFactory: (http: HttpBackend) => new TranslateHttpLoader(new HttpClient(http), './i18n/', '.json'),
      },
    })])
  ]
};
 
export const provideLocalesTest = () => {
  return [
    provideLocales(),
    { provide: HttpBackend, useClass: HttpBackend },
  ]
}