From 4325518917c7367ce6fddc8ba5a519cead7adf63 Mon Sep 17 00:00:00 2001 From: Pavel Maskevich Date: Sat, 21 Sep 2024 21:11:36 +0200 Subject: [PATCH 1/2] issue-20805 fixed bug with wrong lang attribute --- .../src/lib/services/session-state.service.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) 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..7d73c5c4edc 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 @@ -47,9 +47,8 @@ export class SessionStateService { if (lang.includes(';')) { lang = lang.split(';')[0]; } - if (appLanguage !== lang) { - this.setLanguage(lang); - } + + this.setLanguage(lang); }); } @@ -84,9 +83,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 = document.documentElement.getAttribute('lang'); + if (language !== currentAttribute) { + document.documentElement.setAttribute('lang', language); + } } } From daa339517ef4039c68e0b7fa03fcac56802fc2bd Mon Sep 17 00:00:00 2001 From: Masum ULU <49063256+masum-ulu@users.noreply.github.com> Date: Mon, 23 Sep 2024 10:37:24 +0300 Subject: [PATCH 2/2] Update session-state.service.ts --- .../core/src/lib/services/session-state.service.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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 7d73c5c4edc..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)); @@ -89,9 +91,9 @@ export class SessionStateService { this.store.patch({ language }); } - const currentAttribute = document.documentElement.getAttribute('lang'); + const currentAttribute = this.document.documentElement.getAttribute('lang'); if (language !== currentAttribute) { - document.documentElement.setAttribute('lang', language); + this.document.documentElement.setAttribute('lang', language); } } }