import { HttpClient } from '@angular/common/http' ; import { Injectable , NgModule } from '@angular/core' ; import { Translation , translocoConfig , TranslocoConfig , TranslocoLoader , TranslocoMissingHandler , TranslocoModule , TRANSLOCO_CONFIG , TRANSLOCO_LOADER , TRANSLOCO_MISSING_HANDLER , } from '@ngneat/transloco' ; import { of } from 'rxjs' ; import { catchError } from 'rxjs/operators' ; import { environment } from '../../environments/environment' ; export class CustomHandler implements TranslocoMissingHandler { handle ( key , config ) { return key ; } } @ Injectable ( { providedIn : 'root' } ) export class TranslocoHttpLoader implements TranslocoLoader { constructor ( private http ) { } getTranslation ( lang ) { return this . http . get < Translation > ( `${ document . baseURI }assets/i18n/${ lang }.json` ) . pipe ( catchError ( ( ) => of ( { } ) ) ) ; } } @ NgModule ( { exports : [ TranslocoModule ] , providers : [ { provide : TRANSLOCO_CONFIG , useValue : translocoConfig ( { availableLangs : [ 'en' , 'ru' ] , defaultLang : 'en' , reRenderOnLangChange : true , prodMode : environment . production , } ) , } , { provide : TRANSLOCO_LOADER , useClass : TranslocoHttpLoader } , { provide : TRANSLOCO_MISSING_HANDLER , useClass : CustomHandler , } , ] , } ) export class TranslocoRootModule { }