From 80c6017ed0711dc79ae9ae7b96abd697e8bf9e73 Mon Sep 17 00:00:00 2001 From: crusader Date: Sat, 13 Oct 2018 04:59:41 +0900 Subject: [PATCH] ing --- src/app/app.component.ts | 24 +++++++++++++++++------- src/app/service/i18n.service.ts | 4 +--- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 1851beb..a045461 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -40,14 +40,15 @@ export class AppComponent implements OnInit, AfterContentInit, AfterViewInit, On this.showTitleBar = false; this.block = false; - // this.translateService.onLangChange.subscribe(() => { - // this.changeDetector.detectChanges(); + this.translateService.addLangs(['en', 'ko']); + this.translateService.setDefaultLang('en'); + // this.translateService.onLangChange.subscribe((e) => { + // this.changeDetector.markForCheck(); // }); - // this.translateService.onTranslationChange.subscribe(() => { + // this.translateService.onTranslationChange.subscribe((e) => { // this.changeDetector.detectChanges(); // }); - this.translateService.setDefaultLang('en'); // const i18ns = ['en', 'ko']; // i18ns.forEach((lang) => { @@ -67,6 +68,7 @@ export class AppComponent implements OnInit, AfterContentInit, AfterViewInit, On this.menuSubscription = this.electronProxyService.menuObservable() .pipe( map((name: MenuEvent) => { + let requireDetectChanges = true; switch (name) { case 'show-about': this.displayAbout = true; @@ -87,15 +89,23 @@ export class AppComponent implements OnInit, AfterContentInit, AfterViewInit, On this.displayPrint = true; break; case 'change-language-english': - this.translateService.use('en'); + requireDetectChanges = false; + this.translateService.use('en').pipe(take(1)).subscribe((res: any) => { + __this.changeDetector.detectChanges(); + }); break; case 'change-language-korean': - this.translateService.use('ko'); + requireDetectChanges = false; + this.translateService.use('ko').pipe(take(1)).subscribe((res: any) => { + __this.changeDetector.detectChanges(); + }); break; default: break; } - __this.changeDetector.detectChanges(); + if (requireDetectChanges) { + __this.changeDetector.detectChanges(); + } }), catchError(error => { return of(error); diff --git a/src/app/service/i18n.service.ts b/src/app/service/i18n.service.ts index 47de228..8e78f6a 100644 --- a/src/app/service/i18n.service.ts +++ b/src/app/service/i18n.service.ts @@ -4,9 +4,7 @@ import { Observable, of } from 'rxjs'; import { TranslateLoader } from '@ngx-translate/core'; import { ElectronProxyService } from './electron-proxy.service'; -@Injectable({ - providedIn: 'root' -}) +@Injectable() export class I18nService extends TranslateLoader { private prefix: string; private suffix: string;