Correction initialization of language
This commit is contained in:
parent
34a9849414
commit
b863cdff91
|
|
@ -2,18 +2,18 @@
|
||||||
<div class="me-auto col-auto">
|
<div class="me-auto col-auto">
|
||||||
<a class="navbar-brand ms-2">
|
<a class="navbar-brand ms-2">
|
||||||
<a
|
<a
|
||||||
class="navbar-brand ms-2"
|
class="navbar-brand ms-2"
|
||||||
role="button"
|
role="button"
|
||||||
tabindex="0"
|
tabindex="0"
|
||||||
(click)="switchLanguage(translate.currentLang === 'pl' ? 'en' : 'pl')"
|
(click)="switchLanguage( translate.currentLang === 'pl' ? 'en' : 'pl' )"
|
||||||
(keydown)="handleKeyDown($event)">
|
(keydown)="handleKeyDown($event)">
|
||||||
<img
|
<img
|
||||||
loading="lazy"
|
loading="lazy"
|
||||||
class="border border-dark"
|
class="border border-dark"
|
||||||
height="25"
|
height="25"
|
||||||
src="/flag-icons-main/flags/4x3/{{ translate.currentLang === 'pl' ? 'us' : 'pl' }}.svg"
|
src= "/flag-icons-main/flags/4x3/{{ translate.currentLang === 'pl' ? 'us' : 'pl' }}.svg"
|
||||||
alt="Switch language"
|
alt="Switch language"
|
||||||
>
|
>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
</a>
|
</a>
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ export class AppComponent implements OnDestroy {
|
||||||
private langChangeSub!: Subscription;
|
private langChangeSub!: Subscription;
|
||||||
title = 'Strona';
|
title = 'Strona';
|
||||||
|
|
||||||
|
|
||||||
constructor(public translate: TranslateService) {
|
constructor(public translate: TranslateService) {
|
||||||
this.initializeLanguage();
|
this.initializeLanguage();
|
||||||
}
|
}
|
||||||
|
|
@ -24,12 +25,13 @@ export class AppComponent implements OnDestroy {
|
||||||
|
|
||||||
this.translate.addLangs(supportedLangs);
|
this.translate.addLangs(supportedLangs);
|
||||||
|
|
||||||
if (savedLang && supportedLangs.includes(savedLang)) {
|
if( savedLang && supportedLangs.includes(savedLang) ) {
|
||||||
this.translate.use(savedLang);
|
this.switchLanguage(savedLang);
|
||||||
} else {
|
} else {
|
||||||
const browserLang = navigator.language.slice(0, 2);
|
const browserLang = navigator.language.slice(0, 2);
|
||||||
const defaultLang = supportedLangs.includes(browserLang) ? browserLang : 'pl';
|
const defaultLang = supportedLangs.includes(browserLang) ? browserLang : 'pl';
|
||||||
this.translate.setDefaultLang(defaultLang);
|
this.translate.setDefaultLang(defaultLang);
|
||||||
|
this.switchLanguage( defaultLang );
|
||||||
}
|
}
|
||||||
|
|
||||||
this.langChangeSub = this.translate.onLangChange.subscribe((event) => {
|
this.langChangeSub = this.translate.onLangChange.subscribe((event) => {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue