Skip to content

Commit

Permalink
fixed custom mock language
Browse files Browse the repository at this point in the history
1. remoced gl mock implementation
2. introduced scope variable to access current translation
  • Loading branch information
msmannan00 authored and evilaliv3 committed Nov 14, 2024
1 parent 932e1da commit 318f307
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
1 change: 1 addition & 0 deletions client/app/src/app-data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {BehaviorSubject, Observable} from "rxjs";
export class AppDataService {
private showLoadingPanelSubject: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
showLoadingPanel$: Observable<boolean> = this.showLoadingPanelSubject.asObservable();
language:string = "en"

updateShowLoadingPanel(newValue: boolean) {
this.showLoadingPanelSubject.next(newValue);
Expand Down
12 changes: 3 additions & 9 deletions client/app/src/services/helper/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -93,11 +94,4 @@ class MockEngine {
}
}

const GL = {
language: 'en',
get mockEngine() {
return mockEngine;
}
};

export const mockEngine = new MockEngine();
7 changes: 5 additions & 2 deletions client/app/src/services/helper/translation.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ 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",
})
export class TranslationService {
private utilsService = inject(UtilsService);
protected translate = inject(TranslateService);
private document = inject<Document>(DOCUMENT);
private appDataService = inject(AppDataService);

language = "";

Expand All @@ -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();
}
Expand Down

0 comments on commit 318f307

Please sign in to comment.