diff --git a/npm/ng-packs/packages/core/src/lib/services/session-state.service.ts b/npm/ng-packs/packages/core/src/lib/services/session-state.service.ts index 36f7c9e94a8..d6f423983ce 100644 --- a/npm/ng-packs/packages/core/src/lib/services/session-state.service.ts +++ b/npm/ng-packs/packages/core/src/lib/services/session-state.service.ts @@ -1,4 +1,5 @@ -import { Injectable } from '@angular/core'; +import { Injectable, inject } from '@angular/core'; +import { DOCUMENT } from '@angular/common'; import compare from 'just-compare'; import { filter, take } from 'rxjs/operators'; import { Session } from '../models/session'; @@ -12,6 +13,7 @@ import { AbpLocalStorageService } from './local-storage.service'; }) export class SessionStateService { private readonly store = new InternalStore({} as Session.State); + protected readonly document = inject(DOCUMENT); private updateLocalStorage = () => { this.localStorageService.setItem('abpSession', JSON.stringify(this.store.state)); @@ -47,9 +49,8 @@ export class SessionStateService { if (lang.includes(';')) { lang = lang.split(';')[0]; } - if (appLanguage !== lang) { - this.setLanguage(lang); - } + + this.setLanguage(lang); }); } @@ -84,9 +85,15 @@ export class SessionStateService { } setLanguage(language: string) { - if (language === this.store.state.language) return; + const currentLanguage = this.store.state.language; + + if (language !== currentLanguage) { + this.store.patch({ language }); + } - this.store.patch({ language }); - document.documentElement.setAttribute('lang', language); + const currentAttribute = this.document.documentElement.getAttribute('lang'); + if (language !== currentAttribute) { + this.document.documentElement.setAttribute('lang', language); + } } }