I have a very strange behaviour when using translate service. I configure the translator like this :
export class AppComponent implements OnInit {
constructor(
private translateService: TranslateService,
angulartics2GoogleAnalytics: Angulartics2GoogleAnalytics,
angulartics2: Angulartics2,
router: Router,
private googleAnalyticsService: GoogleAnalyticsService,
) {
translateService.setDefaultLang('en');
translateService.use('en');
}
And My HomeComponent :
export class HomePageComponent implements OnInit {
constructor(
private seoService: SeoService,
private translateService: TranslateService
) {
}
ngOnInit() {
this.addPageMeta();
console.log('Add Page Meta');
}
addPageMeta() {
const title = this.translateService.instant('seo.home.title');
const meta: SeoMeta = {
url : '/home',
title: title,
description: this.translateService.instant('seo.home.description'),
};
this.seoService.setPageTitle(title);
this.seoService.addMeta(meta);
}
}
Core.module.ts :
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useFactory: HttpLoaderFactory,
deps: [HttpClient]
}
})
export function HttpLoaderFactory(http: HttpClient) {
return new TranslateHttpLoader(http);
}
When I do a refresh I have in title of my page seo.home.title
so the translation is not done, after that if I swith to another page, after that back to homepage, translations is working. If again a do an F5 translation didn't work. And this problem is everywhere when I load first time page.
Thanks in advance.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…