mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-13 13:03:04 +00:00
63825: UI language cookie
This commit is contained in:
@@ -32,6 +32,10 @@ import { combineLatest as combineLatestObservable, Observable, of } from 'rxjs';
|
||||
import { slideSidebarPadding } from './shared/animations/slide';
|
||||
import { HostWindowService } from './shared/host-window.service';
|
||||
import { Theme } from '../config/theme.inferface';
|
||||
import { ClientCookieService } from './shared/services/client-cookie.service';
|
||||
import { isNotEmpty } from './shared/empty.util';
|
||||
|
||||
export const LANG_COOKIE = 'language_cookie';
|
||||
|
||||
@Component({
|
||||
selector: 'ds-app',
|
||||
@@ -61,6 +65,7 @@ export class AppComponent implements OnInit, AfterViewInit {
|
||||
private cssService: CSSVariableService,
|
||||
private menuService: MenuService,
|
||||
private windowService: HostWindowService,
|
||||
private clientCookie: ClientCookieService
|
||||
) {
|
||||
// Load all the languages that are defined as active from the config file
|
||||
translate.addLangs(config.languages.filter((LangConfig) => LangConfig.active === true).map((a) => a.code));
|
||||
@@ -68,11 +73,20 @@ export class AppComponent implements OnInit, AfterViewInit {
|
||||
// Load the default language from the config file
|
||||
translate.setDefaultLang(config.defaultLanguage);
|
||||
|
||||
// Attempt to get the browser language from the user
|
||||
if (translate.getLangs().includes(translate.getBrowserLang())) {
|
||||
translate.use(translate.getBrowserLang());
|
||||
// Attempt to get the language from a cookie
|
||||
const lang = clientCookie.get(LANG_COOKIE);
|
||||
if (isNotEmpty(lang)) {
|
||||
// Cookie found
|
||||
// Use the language from the cookie
|
||||
translate.use(lang);
|
||||
} else {
|
||||
translate.use(config.defaultLanguage);
|
||||
// Cookie not found
|
||||
// Attempt to get the browser language from the user
|
||||
if (translate.getLangs().includes(translate.getBrowserLang())) {
|
||||
translate.use(translate.getBrowserLang());
|
||||
} else {
|
||||
translate.use(config.defaultLanguage);
|
||||
}
|
||||
}
|
||||
|
||||
metadata.listenForRouteChange();
|
||||
|
Reference in New Issue
Block a user