From e1753294d42e10550ae5c73f5f677a9e1e096c63 Mon Sep 17 00:00:00 2001 From: Yana De Pauw Date: Mon, 24 Oct 2022 17:48:31 +0200 Subject: [PATCH] 96121: Fix server side language headers --- src/app/core/locale/locale.service.ts | 2 +- src/app/core/locale/server-locale.service.ts | 27 ++++++++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/app/core/locale/locale.service.ts b/src/app/core/locale/locale.service.ts index 1052021479..92d35c37d5 100644 --- a/src/app/core/locale/locale.service.ts +++ b/src/app/core/locale/locale.service.ts @@ -40,7 +40,7 @@ export class LocaleService { protected translate: TranslateService, protected authService: AuthService, protected routeService: RouteService, - @Inject(DOCUMENT) private document: any + @Inject(DOCUMENT) protected document: any ) { } diff --git a/src/app/core/locale/server-locale.service.ts b/src/app/core/locale/server-locale.service.ts index f438643e49..556619b946 100644 --- a/src/app/core/locale/server-locale.service.ts +++ b/src/app/core/locale/server-locale.service.ts @@ -1,12 +1,31 @@ import { LANG_ORIGIN, LocaleService } from './locale.service'; -import { Injectable } from '@angular/core'; +import { Inject, Injectable } from '@angular/core'; import { combineLatest, Observable, of as observableOf } from 'rxjs'; import { map, mergeMap, take } from 'rxjs/operators'; -import { isEmpty, isNotEmpty } from '../../shared/empty.util'; +import { hasValue, isEmpty, isNotEmpty } from '../../shared/empty.util'; +import { NativeWindowRef, NativeWindowService } from '../services/window.service'; +import { REQUEST } from '@nguniversal/express-engine/tokens'; +import { CookieService } from '../services/cookie.service'; +import { TranslateService } from '@ngx-translate/core'; +import { AuthService } from '../auth/auth.service'; +import { RouteService } from '../services/route.service'; +import { DOCUMENT } from '@angular/common'; @Injectable() export class ServerLocaleService extends LocaleService { + constructor( + @Inject(NativeWindowService) protected _window: NativeWindowRef, + @Inject(REQUEST) protected req: Request, + protected cookie: CookieService, + protected translate: TranslateService, + protected authService: AuthService, + protected routeService: RouteService, + @Inject(DOCUMENT) protected document: any + ) { + super(_window, cookie, translate, authService, routeService, document); + } + /** * Get the languages list of the user in Accept-Language format * @@ -50,6 +69,10 @@ export class ServerLocaleService extends LocaleService { if (isNotEmpty(epersonLang)) { languages.push(...epersonLang); } + if (hasValue(this.req.headers['accept-language'])) { + languages.push(...this.req.headers['accept-language'].split(',') + ); + } return languages; }) );