From 03143aacae2e90e6ad28d230eb30b81daf287555 Mon Sep 17 00:00:00 2001 From: gkolokythas Date: Wed, 20 Nov 2019 11:04:27 +0200 Subject: [PATCH] Adds language to cookie consent pop up. (Issue #203) --- dmp-frontend/angular.json | 4 +-- dmp-frontend/src/app/app.component.ts | 39 +++++++++++++++++---------- dmp-frontend/src/assets/i18n/en.json | 7 +++++ 3 files changed, 34 insertions(+), 16 deletions(-) diff --git a/dmp-frontend/angular.json b/dmp-frontend/angular.json index 957144b7f..6de6bf84c 100644 --- a/dmp-frontend/angular.json +++ b/dmp-frontend/angular.json @@ -24,10 +24,10 @@ "src/styles.scss", "src/assets/scss/material-dashboard.scss", "src/assets/css/demo.css", - "../dmp-frontend/node_modules/cookieconsent/build/cookieconsent.min.css" + "node_modules/cookieconsent/build/cookieconsent.min.css" ], "scripts": [ - "../dmp-frontend/node_modules/cookieconsent/build/cookieconsent.min.js" + "node_modules/cookieconsent/build/cookieconsent.min.js" ] }, "configurations": { diff --git a/dmp-frontend/src/app/app.component.ts b/dmp-frontend/src/app/app.component.ts index c6f300902..013a2c0f5 100644 --- a/dmp-frontend/src/app/app.component.ts +++ b/dmp-frontend/src/app/app.component.ts @@ -36,7 +36,6 @@ export class AppComponent implements OnInit { private translate: TranslateService, private breadCrumbResolverService: BreadCrumbResolverService, private titleService: Title, - private language: TranslateService, private cultureService: CultureService, private cookieService: CookieService, private ccService: NgcCookieConsentService @@ -80,29 +79,41 @@ export class AppComponent implements OnInit { }) ).subscribe((ttl: string) => { if (ttl.length > 0) { - this.language.get(ttl).subscribe((translated: string) => { - this.language.get('GENERAL.TITLES.PREFIX').subscribe((titlePrefix: string) => { + this.translate.get(ttl).subscribe((translated: string) => { + this.translate.get('GENERAL.TITLES.PREFIX').subscribe((titlePrefix: string) => { this.titleService.setTitle(titlePrefix + translated); }); }); } else { - this.language.get('GENERAL.TITLES.GENERAL').subscribe((translated: string) => { + this.translate.get('GENERAL.TITLES.GENERAL').subscribe((translated: string) => { this.titleService.setTitle(translated); }); } }); - this.statusChangeSubscription = this.ccService.statusChange$ - .subscribe((event: NgcStatusChangeEvent) => { - if (event.status == "dismiss") { - this.cookieService.set("cookiesConsent", "true", 365); + this.statusChangeSubscription = this.ccService.statusChange$.subscribe((event: NgcStatusChangeEvent) => { + if (event.status == "dismiss") { + this.cookieService.set("cookiesConsent", "true", 365); + } + }); + + this.translate + .get(['COOKIE.MESSAGE', 'COOKIE.DISMISS', 'COOKIE.DENY', 'COOKIE.LINK', 'COOKIE.POLICY']) + .subscribe(data => { + this.ccService.getConfig().content = this.ccService.getConfig().content || {}; + // Override default messages with the translated ones + this.ccService.getConfig().content.message = data['COOKIE.MESSAGE']; + this.ccService.getConfig().content.dismiss = data['COOKIE.DISMISS']; + this.ccService.getConfig().content.deny = data['COOKIE.DENY']; + this.ccService.getConfig().content.link = data['COOKIE.LINK']; + this.ccService.getConfig().content.policy = data['COOKIE.POLICY']; + + if (this.cookieService.get("cookiesConsent") == "true") { + this.ccService.getConfig().enabled = false; } - }); - if (this.cookieService.get("cookiesConsent") == "true") { - this.ccService.getConfig().enabled = false; - this.ccService.destroy(); - this.ccService.init(this.ccService.getConfig()); - } + this.ccService.destroy(); + this.ccService.init(this.ccService.getConfig()); + }) } ngOnDestroy() { diff --git a/dmp-frontend/src/assets/i18n/en.json b/dmp-frontend/src/assets/i18n/en.json index 66188ce15..d522a0033 100644 --- a/dmp-frontend/src/assets/i18n/en.json +++ b/dmp-frontend/src/assets/i18n/en.json @@ -116,6 +116,13 @@ "DOC": "Document" } }, + "COOKIE": { + "MESSAGE": "This website uses cookies to enhance the user experience.", + "DISMISS": "Got it!", + "DENY": "Refuse cookies", + "LINK": "Learn more", + "POLICY": "Cookie Policy" + }, "EMAIL-CONFIRMATION": { "EXPIRED-EMAIL": "Mail invitation expired", "CARD-TITLE": "E-mail",