From 1918c43de8c89f3b830978bbc29302ef4eece621 Mon Sep 17 00:00:00 2001 From: Bastian Jakobi <55296998+bastianjakobi@users.noreply.github.com> Date: Tue, 24 Sep 2024 11:44:30 +0200 Subject: [PATCH] refactor: add primelocale loading to app.component,ts (#308) --- src/app/app.component.ts | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 8f5f6c2..c919728 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -1,10 +1,33 @@ -import { Component } from '@angular/core'; +import { Component, OnInit } from '@angular/core' +import { TranslateService } from '@ngx-translate/core' +import { UserService } from '@onecx/angular-integration-interface' +import { PrimeNGConfig } from 'primeng/api' +import { merge, mergeMap } from 'rxjs' @Component({ selector: 'ocx-shell-root', templateUrl: './app.component.html', - styleUrls: ['./app.component.scss'], + styleUrls: ['./app.component.scss'] }) -export class AppComponent { - title = 'shell'; +export class AppComponent implements OnInit { + title = 'shell' + + constructor( + private translateService: TranslateService, + private config: PrimeNGConfig, + private userService: UserService + ) {} + + ngOnInit(): void { + this.userService.lang$.subscribe((lang) => { + this.translateService.use(lang) + }) + merge( + this.translateService.onLangChange, + this.translateService.onTranslationChange, + this.translateService.onDefaultLangChange + ) + .pipe(mergeMap(() => this.translateService.get('primeng'))) + .subscribe((res) => this.config.setTranslation(res)) + } }