]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/shared/guards/can-deactivate-guard.service.ts
Move send video components inside a dedicated directory
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / guards / can-deactivate-guard.service.ts
index 15618f6990a41d1836cc28738476880d1f300516..c038a5c0edae4dd81ead969cd6c361d534575605 100644 (file)
@@ -1,7 +1,8 @@
 import { Injectable } from '@angular/core'
-import { CanDeactivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router'
-import { Observable } from 'rxjs/Observable'
+import { ActivatedRouteSnapshot, CanDeactivate, RouterStateSnapshot } from '@angular/router'
+import { Observable } from 'rxjs'
 import { ConfirmService } from '../../core/index'
+import { I18n } from '@ngx-translate/i18n-polyfill'
 
 export interface CanComponentDeactivate {
   canDeactivate: () => { text?: string, canDeactivate: Observable<boolean> | boolean }
@@ -9,19 +10,22 @@ export interface CanComponentDeactivate {
 
 @Injectable()
 export class CanDeactivateGuard implements CanDeactivate<CanComponentDeactivate> {
-  constructor (private confirmService: ConfirmService) { }
+  constructor (
+    private confirmService: ConfirmService,
+    private i18n: I18n
+  ) { }
 
   canDeactivate (component: CanComponentDeactivate,
     currentRoute: ActivatedRouteSnapshot,
     currentState: RouterStateSnapshot,
     nextState: RouterStateSnapshot
-  ): Observable<boolean> | boolean {
+  ) {
     const result = component.canDeactivate()
-    const text = result.text || 'All unsaved data will be lost, are you sure you want to leave this page?'
+    const text = result.text || this.i18n('All unsaved data will be lost, are you sure you want to leave this page?')
 
     return result.canDeactivate || this.confirmService.confirm(
       text,
-      'Warning'
+      this.i18n('Warning')
     )
   }