mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
Merge pull request #1287 from atmire/language-attribute-html-tag
Language attribute on HTML tag
This commit is contained in:
@@ -21,6 +21,7 @@ describe('LocaleService test suite', () => {
|
|||||||
let spyOnSet;
|
let spyOnSet;
|
||||||
let authService;
|
let authService;
|
||||||
let routeService;
|
let routeService;
|
||||||
|
let document;
|
||||||
|
|
||||||
authService = jasmine.createSpyObj('AuthService', {
|
authService = jasmine.createSpyObj('AuthService', {
|
||||||
isAuthenticated: jasmine.createSpy('isAuthenticated'),
|
isAuthenticated: jasmine.createSpy('isAuthenticated'),
|
||||||
@@ -43,6 +44,7 @@ describe('LocaleService test suite', () => {
|
|||||||
{ provide: CookieService, useValue: new CookieServiceMock() },
|
{ provide: CookieService, useValue: new CookieServiceMock() },
|
||||||
{ provide: AuthService, userValue: authService },
|
{ provide: AuthService, userValue: authService },
|
||||||
{ provide: RouteService, useValue: routeServiceStub },
|
{ provide: RouteService, useValue: routeServiceStub },
|
||||||
|
{ provide: Document, useValue: document },
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
@@ -52,7 +54,8 @@ describe('LocaleService test suite', () => {
|
|||||||
translateService = TestBed.inject(TranslateService);
|
translateService = TestBed.inject(TranslateService);
|
||||||
routeService = TestBed.inject(RouteService);
|
routeService = TestBed.inject(RouteService);
|
||||||
window = new NativeWindowRef();
|
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;
|
serviceAsAny = service;
|
||||||
spyOnGet = spyOn(cookieService, 'get');
|
spyOnGet = spyOn(cookieService, 'get');
|
||||||
spyOnSet = spyOn(cookieService, 'set');
|
spyOnSet = spyOn(cookieService, 'set');
|
||||||
@@ -114,6 +117,12 @@ describe('LocaleService test suite', () => {
|
|||||||
expect(translateService.use).toHaveBeenCalledWith('es');
|
expect(translateService.use).toHaveBeenCalledWith('es');
|
||||||
expect(service.saveLanguageCodeToCookie).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('', () => {
|
describe('', () => {
|
||||||
|
@@ -10,6 +10,7 @@ import { combineLatest, Observable, of as observableOf } from 'rxjs';
|
|||||||
import { map, mergeMap, take } from 'rxjs/operators';
|
import { map, mergeMap, take } from 'rxjs/operators';
|
||||||
import { NativeWindowRef, NativeWindowService } from '../services/window.service';
|
import { NativeWindowRef, NativeWindowService } from '../services/window.service';
|
||||||
import { RouteService } from '../services/route.service';
|
import { RouteService } from '../services/route.service';
|
||||||
|
import { DOCUMENT } from '@angular/common';
|
||||||
|
|
||||||
export const LANG_COOKIE = 'dsLanguage';
|
export const LANG_COOKIE = 'dsLanguage';
|
||||||
|
|
||||||
@@ -38,7 +39,9 @@ export class LocaleService {
|
|||||||
protected cookie: CookieService,
|
protected cookie: CookieService,
|
||||||
protected translate: TranslateService,
|
protected translate: TranslateService,
|
||||||
protected authService: AuthService,
|
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.translate.use(lang);
|
||||||
this.saveLanguageCodeToCookie(lang);
|
this.saveLanguageCodeToCookie(lang);
|
||||||
|
this.document.documentElement.lang = lang;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user