From 6f9dbe4942737f7c221ecb51e146cc54af6d7958 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D8=B9=D8=A8=D8=AF=D8=A7=D9=84=D9=85=D9=86=D8=A7=D9=86?= Date: Thu, 14 Nov 2024 17:36:38 +0500 Subject: [PATCH] fixed custom mock language 1. remoced gl mock implementation 2. introduced scope variable to access current translation --- client/app/src/app-data.service.ts | 1 + client/app/src/services/helper/mocks.ts | 12 +++--------- .../app/src/services/helper/translation.service.ts | 7 +++++-- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/client/app/src/app-data.service.ts b/client/app/src/app-data.service.ts index 07fce50694..fbd12d6b82 100644 --- a/client/app/src/app-data.service.ts +++ b/client/app/src/app-data.service.ts @@ -9,6 +9,7 @@ import {BehaviorSubject, Observable} from "rxjs"; export class AppDataService { private showLoadingPanelSubject: BehaviorSubject = new BehaviorSubject(false); showLoadingPanel$: Observable = this.showLoadingPanelSubject.asObservable(); + language:string = "en" updateShowLoadingPanel(newValue: boolean) { this.showLoadingPanelSubject.next(newValue); diff --git a/client/app/src/services/helper/mocks.ts b/client/app/src/services/helper/mocks.ts index 3cb58b55b6..acc6c82a87 100644 --- a/client/app/src/services/helper/mocks.ts +++ b/client/app/src/services/helper/mocks.ts @@ -14,13 +14,14 @@ interface Mocks { } class MockEngine { + language: string private mocks: Mocks = {}; private applyMock(mock: Mock): void { const e = document.querySelector(mock.selector) as HTMLElement | null; if (e) { - if (!mock.value || mock.language !== GL.language) { - mock.language = GL.language; + if (!mock.value || mock.language !== this.language) { + mock.language = this.language; if (typeof mock.mock === "function") { mock.value = mock.mock(e); } else { @@ -93,11 +94,4 @@ class MockEngine { } } -const GL = { - language: 'en', - get mockEngine() { - return mockEngine; - } -}; - export const mockEngine = new MockEngine(); \ No newline at end of file diff --git a/client/app/src/services/helper/translation.service.ts b/client/app/src/services/helper/translation.service.ts index 351a51c3f5..566de73c23 100644 --- a/client/app/src/services/helper/translation.service.ts +++ b/client/app/src/services/helper/translation.service.ts @@ -2,7 +2,8 @@ import {BehaviorSubject} from 'rxjs'; import {Injectable, inject} from "@angular/core"; import {TranslateService} from "@ngx-translate/core"; import {UtilsService} from "@app/shared/services/utils.service"; -import {DOCUMENT} from "@angular/common"; +import {AppDataService} from "@app/app-data.service"; +import {mockEngine} from "@app/services/helper/mocks"; @Injectable({ providedIn: "root", @@ -10,7 +11,7 @@ import {DOCUMENT} from "@angular/common"; export class TranslationService { private utilsService = inject(UtilsService); protected translate = inject(TranslateService); - private document = inject(DOCUMENT); + private appDataService = inject(AppDataService); language = ""; @@ -31,6 +32,8 @@ export class TranslationService { this.language = changedLanguage; this.changeLocale(this.language); this.translate.use(this.language).subscribe(() => { + this.appDataService.language = this.language + mockEngine.language = this.language if (callback) { callback(); }