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;