Correction initialization of language

This commit is contained in:
Artur 2024-11-19 19:34:24 +01:00
parent 34a9849414
commit b863cdff91
2 changed files with 16 additions and 14 deletions

View File

@ -14,6 +14,7 @@ export class AppComponent implements OnDestroy {
private langChangeSub!: Subscription;
title = 'Strona';
constructor(public translate: TranslateService) {
this.initializeLanguage();
}
@ -25,11 +26,12 @@ export class AppComponent implements OnDestroy {
this.translate.addLangs(supportedLangs);
if( savedLang && supportedLangs.includes(savedLang) ) {
this.translate.use(savedLang);
this.switchLanguage(savedLang);
} else {
const browserLang = navigator.language.slice(0, 2);
const defaultLang = supportedLangs.includes(browserLang) ? browserLang : 'pl';
this.translate.setDefaultLang(defaultLang);
this.switchLanguage( defaultLang );
}
this.langChangeSub = this.translate.onLangChange.subscribe((event) => {