From 6617a5ce8d038bf0b6eeadd35b04761d18b52a0d Mon Sep 17 00:00:00 2001
From: Alex ORLUC <alex.orluc@maarch.org>
Date: Tue, 30 Apr 2019 17:39:56 +0200
Subject: [PATCH] FEAT #10383 TIME 1 add lang in client cache

---
 src/frontend/app/app.component.ts             | 9 ++++++++-
 src/frontend/app/login/login.component.ts     | 2 +-
 src/frontend/app/profile/profile.component.ts | 1 +
 3 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/frontend/app/app.component.ts b/src/frontend/app/app.component.ts
index eaae4002b6..bddb3e7163 100755
--- a/src/frontend/app/app.component.ts
+++ b/src/frontend/app/app.component.ts
@@ -16,7 +16,14 @@ import { TranslateService } from '@ngx-translate/core';
 export class AppComponent {
 
   constructor(private translate: TranslateService, public http: HttpClient, public signaturesService: SignaturesContentService, public sanitizer: DomSanitizer, private cookieService: CookieService, public notificationService: NotificationService) {
-    translate.setDefaultLang('fr');
+
+    if (this.cookieService.check('maarchParapheurLang')) {
+      const cookieInfoLang = this.cookieService.get('maarchParapheurLang');
+      translate.setDefaultLang(cookieInfoLang);
+    } else {
+      this.cookieService.set( 'maarchParapheurLang', 'fr' );
+      translate.setDefaultLang('fr');
+    }
 
     if (this.cookieService.check('maarchParapheurAuth')) {
       const cookieInfo = JSON.parse(atob(this.cookieService.get('maarchParapheurAuth')));
diff --git a/src/frontend/app/login/login.component.ts b/src/frontend/app/login/login.component.ts
index e1ae9163aa..4e372827eb 100644
--- a/src/frontend/app/login/login.component.ts
+++ b/src/frontend/app/login/login.component.ts
@@ -10,7 +10,6 @@ import { NotificationService } from '../service/notification.service';
 import { environment } from '../../core/environments/environment';
 import { TranslateService } from '@ngx-translate/core';
 import { Validators, FormControl } from '@angular/forms';
-import { last } from '@angular/router/src/utils/collection';
 
 @Component({
     templateUrl: 'login.component.html',
@@ -81,6 +80,7 @@ export class LoginComponent implements OnInit, AfterViewInit {
                 this.signaturesService.userLogged = data.user;
 
                 this.translate.use(this.signaturesService.userLogged.preferences.lang);
+                this.cookieService.set( 'maarchParapheurLang', this.signaturesService.userLogged.preferences.lang );
 
                 this.loadingForm = true;
                 $('.maarchLogo').css({ 'transform': 'translateY(0px)' });
diff --git a/src/frontend/app/profile/profile.component.ts b/src/frontend/app/profile/profile.component.ts
index 5e0d5591fa..eed31f9704 100644
--- a/src/frontend/app/profile/profile.component.ts
+++ b/src/frontend/app/profile/profile.component.ts
@@ -209,6 +209,7 @@ export class ProfileComponent implements OnInit {
                 this.signaturesService.userLogged.preferences = data.user.preferences;
                 this.profileInfo.picture = data.user.picture;
                 this.setLang(this.signaturesService.userLogged.preferences.lang);
+                this.cookieService.set( 'maarchParapheurLang', this.signaturesService.userLogged.preferences.lang );
 
                 $('.avatarProfile').css({ 'transform': 'rotate(0deg)' });
 
-- 
GitLab