I have created a app in Angular 5 using ionic 3 but ngx-translate is not loading the correctly. I used lazy-loading in every page.
app.module.ts
import { TranslateModule, TranslateLoader } from '@ngx-translate/core';
import { TranslateHttpLoader } from '@ngx-translate/http-loader';
import {HttpClientModule, HttpClient} from '@angular/common/http';
export function createTranslateLoader(http: HttpClient) {
console.log("TranslateLoader");
return new TranslateHttpLoader(http, './assets/i18n', '.json');
}
imports: [
HttpClientModule,
......
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useFactory: (createTranslateLoader),
deps: [HttpClient]
}
}),
.....
]
app.component.ts
constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen, public translate: TranslateService) {
this.initTranslate();
platform.ready().then(() => {
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
console.log("Loaded Page");
statusBar.styleDefault();
splashScreen.hide();
});
}
initTranslate() {
this.translate.addLangs(["en", "hi"]);
this.translate.setDefaultLang('en');
this.translate.use('en');
this.translate.get("HOME").subscribe((res: string) => {
console.log(res);
});
}
en.json
{
"HOME":"Home"
}
As my json stated my log should print Home
but its printing the HOME
. point out what mistake I’m doing? Any help would be Appreciated Thanks.