diff --git a/src/app/core/locale/locale.service.spec.ts b/src/app/core/locale/locale.service.spec.ts index cee2945253..c7c59802fd 100644 --- a/src/app/core/locale/locale.service.spec.ts +++ b/src/app/core/locale/locale.service.spec.ts @@ -21,6 +21,7 @@ describe('LocaleService test suite', () => { let spyOnSet; let authService; let routeService; + let document; authService = jasmine.createSpyObj('AuthService', { isAuthenticated: jasmine.createSpy('isAuthenticated'), @@ -43,6 +44,7 @@ describe('LocaleService test suite', () => { { provide: CookieService, useValue: new CookieServiceMock() }, { provide: AuthService, userValue: authService }, { provide: RouteService, useValue: routeServiceStub }, + { provide: Document, useValue: document }, ] }); })); @@ -52,7 +54,8 @@ describe('LocaleService test suite', () => { translateService = TestBed.inject(TranslateService); routeService = TestBed.inject(RouteService); window = new NativeWindowRef(); - service = new LocaleService(window, cookieService, translateService, authService, routeService); + document = { documentElement: { lang: 'en' } }; + service = new LocaleService(window, cookieService, translateService, authService, routeService, document); serviceAsAny = service; spyOnGet = spyOn(cookieService, 'get'); spyOnSet = spyOn(cookieService, 'set'); @@ -114,6 +117,12 @@ describe('LocaleService test suite', () => { expect(translateService.use).toHaveBeenCalledWith('es'); expect(service.saveLanguageCodeToCookie).toHaveBeenCalledWith('es'); }); + + it('should set the current language on the html tag', () => { + spyOn(service, 'getCurrentLanguageCode').and.returnValue('es'); + service.setCurrentLanguageCode(); + expect((service as any).document.documentElement.lang).toEqual('es'); + }); }); describe('', () => { diff --git a/src/app/core/locale/locale.service.ts b/src/app/core/locale/locale.service.ts index c73b297e40..1052021479 100644 --- a/src/app/core/locale/locale.service.ts +++ b/src/app/core/locale/locale.service.ts @@ -10,6 +10,7 @@ import { combineLatest, Observable, of as observableOf } from 'rxjs'; import { map, mergeMap, take } from 'rxjs/operators'; import { NativeWindowRef, NativeWindowService } from '../services/window.service'; import { RouteService } from '../services/route.service'; +import { DOCUMENT } from '@angular/common'; export const LANG_COOKIE = 'dsLanguage'; @@ -38,7 +39,9 @@ export class LocaleService { protected cookie: CookieService, protected translate: TranslateService, protected authService: AuthService, - protected routeService: RouteService) { + protected routeService: RouteService, + @Inject(DOCUMENT) private document: any + ) { } /** @@ -148,6 +151,7 @@ export class LocaleService { } this.translate.use(lang); this.saveLanguageCodeToCookie(lang); + this.document.documentElement.lang = lang; } /**