Default language from browser.
This commit is contained in:
parent
c553353741
commit
38e904857c
|
|
@ -9,10 +9,26 @@ import { TranslateService, TranslateModule} from "@ngx-translate/core";
|
|||
styleUrl: './app.component.css'
|
||||
})
|
||||
export class AppComponent {
|
||||
|
||||
|
||||
constructor( public translate: TranslateService ){
|
||||
|
||||
|
||||
this.translate.addLangs(['pl', 'en']);
|
||||
|
||||
// Ustaw domyślny język aplikacji
|
||||
this.translate.setDefaultLang('pl');
|
||||
this.translate.use('pl');
|
||||
|
||||
// Pobierz język przeglądarki i obetnij kod regionu // np. 'en' z 'en-US'
|
||||
const browserLang = navigator.language .slice(0, 2);
|
||||
// Wyświetl w konsoli dla weryfikacji
|
||||
console.log('Język przeglądarki krótki:', browserLang);
|
||||
|
||||
|
||||
// Ustaw język pobrany z przeglądarki, jeśli jest obsługiwany
|
||||
this.translate.use(browserLang.match(/en|pl/) ? browserLang : 'pl');
|
||||
|
||||
|
||||
}
|
||||
|
||||
// app.component.ts
|
||||
|
|
@ -20,5 +36,5 @@ export class AppComponent {
|
|||
this.translate.use(language);
|
||||
}
|
||||
|
||||
title = 'arti-angular-app';
|
||||
title = 'Strona';
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue