Created
April 10, 2020 01:14
-
-
Save kutanov/541b23e5402e2c0aa7c443e0296e3022 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { HttpClient } from '@angular/common/http'; | |
import { | |
TRANSLOCO_LOADER, | |
Translation, | |
TranslocoLoader, | |
TRANSLOCO_CONFIG, | |
translocoConfig, | |
TranslocoModule | |
} from '@ngneat/transloco'; | |
import { Injectable, NgModule } from '@angular/core'; | |
import { environment } from '../environments/environment'; | |
@Injectable({ providedIn: 'root' }) | |
export class TranslocoHttpLoader implements TranslocoLoader { | |
constructor(private http: HttpClient) {} | |
getTranslation(lang: string) { | |
return this.http.get<Translation>(`/assets/i18n/${lang}.json`); | |
} | |
} | |
@NgModule({ | |
exports: [ TranslocoModule ], | |
providers: [ | |
{ | |
provide: TRANSLOCO_CONFIG, | |
useValue: translocoConfig({ | |
availableLangs: ['en', 'ru'], | |
fallbackLang: 'en', | |
defaultLang: 'en', | |
// Remove this option if your application doesn't support changing language in runtime. | |
reRenderOnLangChange: true, | |
prodMode: environment.production, | |
flatten: { | |
aot: environment.production | |
} | |
}) | |
}, | |
{ provide: TRANSLOCO_LOADER, useClass: TranslocoHttpLoader } | |
] | |
}) | |
export class TranslocoRootModule {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment