Skip to content

Commit e175329

Browse files
committed
96121: Fix server side language headers
1 parent e4f483c commit e175329

2 files changed

Lines changed: 26 additions & 3 deletions

File tree

src/app/core/locale/locale.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export class LocaleService {
4040
protected translate: TranslateService,
4141
protected authService: AuthService,
4242
protected routeService: RouteService,
43-
@Inject(DOCUMENT) private document: any
43+
@Inject(DOCUMENT) protected document: any
4444
) {
4545
}
4646

src/app/core/locale/server-locale.service.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,31 @@
11
import { LANG_ORIGIN, LocaleService } from './locale.service';
2-
import { Injectable } from '@angular/core';
2+
import { Inject, Injectable } from '@angular/core';
33
import { combineLatest, Observable, of as observableOf } from 'rxjs';
44
import { map, mergeMap, take } from 'rxjs/operators';
5-
import { isEmpty, isNotEmpty } from '../../shared/empty.util';
5+
import { hasValue, isEmpty, isNotEmpty } from '../../shared/empty.util';
6+
import { NativeWindowRef, NativeWindowService } from '../services/window.service';
7+
import { REQUEST } from '@nguniversal/express-engine/tokens';
8+
import { CookieService } from '../services/cookie.service';
9+
import { TranslateService } from '@ngx-translate/core';
10+
import { AuthService } from '../auth/auth.service';
11+
import { RouteService } from '../services/route.service';
12+
import { DOCUMENT } from '@angular/common';
613

714
@Injectable()
815
export class ServerLocaleService extends LocaleService {
916

17+
constructor(
18+
@Inject(NativeWindowService) protected _window: NativeWindowRef,
19+
@Inject(REQUEST) protected req: Request,
20+
protected cookie: CookieService,
21+
protected translate: TranslateService,
22+
protected authService: AuthService,
23+
protected routeService: RouteService,
24+
@Inject(DOCUMENT) protected document: any
25+
) {
26+
super(_window, cookie, translate, authService, routeService, document);
27+
}
28+
1029
/**
1130
* Get the languages list of the user in Accept-Language format
1231
*
@@ -50,6 +69,10 @@ export class ServerLocaleService extends LocaleService {
5069
if (isNotEmpty(epersonLang)) {
5170
languages.push(...epersonLang);
5271
}
72+
if (hasValue(this.req.headers['accept-language'])) {
73+
languages.push(...this.req.headers['accept-language'].split(',')
74+
);
75+
}
5376
return languages;
5477
})
5578
);

0 commit comments

Comments
 (0)