My website supports 5 different languages with English as the default. When I switch languages in the header component...
header.component.ts
onSetLanguage(lang: string) {
this.trans.use(lang);
this.currentLang = localStorage.setItem("currentLang", lang);
}
and in my app.component.ts
constructor(
private authService: AuthService,
private translate: TranslateService
) {
this.translate.setDefaultLang("en");
const currentLang = localStorage.getItem("currentLang");
if (currentLang !== null) {
this.translate.use(currentLang);
} else {
this.translate.use("en");
}
}
However, a problem arises when I log in for the first time and the current language returns null. If I switch to a different language...
when I submit the form and change the language to Italian (it) before submitting, it still submits the previous language (de) until I refresh the page or navigate back and forth between components.
How can I resolve this issue?