My app.component
looks like this:
export class AppComponent {
public constructor(public translate: TranslateService) {
const userLang = navigator.language.split('-')[0];
const acceptedUserLang = /(de|en)/gi.test(userLang) ? userLang : 'en';
this.translate.setDefaultLang('en');
this.translate.use(acceptedUserLang);
}
}
My app.routing
has the following definition:
const appRoutes: Routes = [
{path: 'signUpSuccess/:language', component: SignUpSuccessComponent},
];
And my signUpSuccess.component
:
export class SignUpSuccessComponent {
public constructor(translate: TranslateService, route: ActivatedRoute) {
translate.use(route.snapshot.params['language']);
}
}
When I load the page with /signUpSuccess/de
, app.component
sets the language to en
, ng2-translate
starts to fetch the en.json
from the server, then signUpSuccess.component
sets the language to de
, ng2-translate
starts t fetch the de.json
from the server. If, for any reason now de.json
wins the race and arrives first at the client, then the language will switch to en
when the en.json
arrives the client. How can I avoid this?