From 72daadee7edd7bd947cee778d086f12c0ac7ea20 Mon Sep 17 00:00:00 2001 From: Diamantis Tziotzios Date: Sat, 11 Feb 2023 14:38:13 +0200 Subject: [PATCH] configurable list of languages --- dmp-frontend/angular.json | 1 - .../configuration/configuration.service.ts | 6 +++ .../services/language/language.service.ts | 4 +- .../language-content/language.component.ts | 13 +++--- .../src/app/ui/navbar/navbar.component.ts | 29 ++++++------- .../user-profile/user-profile-editor.model.ts | 3 +- .../ui/user-profile/user-profile.component.ts | 13 +++--- dmp-frontend/src/assets/config/config.json | 42 +++++++++++++++++++ .../src/assets/resources/language.json | 42 ------------------- 9 files changed, 77 insertions(+), 76 deletions(-) delete mode 100644 dmp-frontend/src/assets/resources/language.json diff --git a/dmp-frontend/angular.json b/dmp-frontend/angular.json index c1a3f7752..4c12d5745 100644 --- a/dmp-frontend/angular.json +++ b/dmp-frontend/angular.json @@ -30,7 +30,6 @@ "scripts": [ "node_modules/cookieconsent/build/cookieconsent.min.js", "node_modules/tinymce/tinymce.min.js" - ], "vendorChunk": true, "extractLicenses": false, diff --git a/dmp-frontend/src/app/core/services/configuration/configuration.service.ts b/dmp-frontend/src/app/core/services/configuration/configuration.service.ts index 64082cb55..469f1fce9 100644 --- a/dmp-frontend/src/app/core/services/configuration/configuration.service.ts +++ b/dmp-frontend/src/app/core/services/configuration/configuration.service.ts @@ -41,6 +41,11 @@ export class ConfigurationService extends BaseComponent { return this._defaultLanguage; } + private _availableLanguages: any[] = []; + get availableLanguages(): any[] { + return this._availableLanguages; + } + private _loginProviders: LoginProviders; get loginProviders(): LoginProviders { return this._loginProviders; @@ -127,6 +132,7 @@ export class ConfigurationService extends BaseComponent { this._helpService = HelpService.parseValue(config.HelpService); this._defaultCulture = config.defaultCulture; this._defaultLanguage = config.defaultLanguage; + this._availableLanguages = config.availableLanguages; this._loginProviders = LoginProviders.parseValue(config.loginProviders); this._logging = Logging.parseValue(config.logging); this._lockInterval = config.lockInterval; diff --git a/dmp-frontend/src/app/core/services/language/language.service.ts b/dmp-frontend/src/app/core/services/language/language.service.ts index b37a36b20..4b343591d 100644 --- a/dmp-frontend/src/app/core/services/language/language.service.ts +++ b/dmp-frontend/src/app/core/services/language/language.service.ts @@ -7,8 +7,6 @@ import { BaseHttpService } from '../http/base-http.service'; import { Language } from '@app/models/language/Language'; import { ConfigurationService } from '../configuration/configuration.service'; -const availableLanguages: any[] = require('../../../../assets/resources/language.json'); - @Injectable() export class LanguageService { private currentLanguage: string; @@ -43,7 +41,7 @@ export class LanguageService { public getCurrentLanguageName() { let result: string = ''; - availableLanguages.forEach(language => { + this.configurationService.availableLanguages.forEach(language => { if (language.value === this.currentLanguage) { result = this.translate.instant(language.label); } diff --git a/dmp-frontend/src/app/ui/language/language-content/language.component.ts b/dmp-frontend/src/app/ui/language/language-content/language.component.ts index 9eff5109f..e27bf0258 100644 --- a/dmp-frontend/src/app/ui/language/language-content/language.component.ts +++ b/dmp-frontend/src/app/ui/language/language-content/language.component.ts @@ -5,8 +5,7 @@ import { LanguageService } from '@app/core/services/language/language.service'; import { UserService } from '@app/core/services/user/user.service'; import { takeUntil } from 'rxjs/operators'; import { BaseComponent } from '@common/base/base.component'; - -const availableLanguages: any[] = require('../../../../assets/resources/language.json'); +import { ConfigurationService } from '@app/core/services/configuration/configuration.service'; @Component({ selector: 'app-language', @@ -16,14 +15,18 @@ const availableLanguages: any[] = require('../../../../assets/resources/language export class LanguageComponent extends BaseComponent implements OnInit { @Output() languageChange: EventEmitter = new EventEmitter(); - languages = availableLanguages; + languages = []; constructor( private router: Router, private authentication: AuthService, private languageService: LanguageService, - private userService: UserService - ) { super(); } + private userService: UserService, + private configurationService:ConfigurationService + ) { + super(); + this.languages = this.configurationService.availableLanguages; + } ngOnInit() { this.languageChange.emit(this.getCurrentLanguage().value) diff --git a/dmp-frontend/src/app/ui/navbar/navbar.component.ts b/dmp-frontend/src/app/ui/navbar/navbar.component.ts index 8b1185d4e..dc208f73a 100644 --- a/dmp-frontend/src/app/ui/navbar/navbar.component.ts +++ b/dmp-frontend/src/app/ui/navbar/navbar.component.ts @@ -1,29 +1,24 @@ import { Location } from '@angular/common'; +import { HttpClient } from '@angular/common/http'; import { Component, ElementRef, EventEmitter, OnInit, Output, ViewChild } from '@angular/core'; import { MatDialog } from '@angular/material/dialog'; import { MatMenuTrigger } from '@angular/material/menu'; import { Router } from '@angular/router'; import { AppRole } from '@app/core/common/enum/app-role'; +import { UserListingModel } from '@app/core/model/user/user-listing'; import { AuthService } from '@app/core/services/auth/auth.service'; +import { ConfigurationService } from '@app/core/services/configuration/configuration.service'; +import { LanguageService } from '@app/core/services/language/language.service'; +import { MatomoService } from '@app/core/services/matomo/matomo-service'; import { ProgressIndicationService } from '@app/core/services/progress-indication/progress-indication-service'; +import { SideNavService } from '@app/core/services/sidenav/side-nav.sevice'; +import { UserService } from '@app/core/services/user/user.service'; import { BaseComponent } from '@common/base/base.component'; import { takeUntil } from 'rxjs/operators'; +import { StartNewDmpDialogComponent } from '../dmp/start-new-dmp-dialogue/start-new-dmp-dialog.component'; +import { FaqDialogComponent } from '../faq/dialog/faq-dialog.component'; import { UserDialogComponent } from '../misc/navigation/user-dialog/user-dialog.component'; import { DATASETS_ROUTES, DMP_ROUTES, GENERAL_ROUTES } from '../sidebar/sidebar.component'; -import { LanguageService } from '@app/core/services/language/language.service'; -import { UserService } from '@app/core/services/user/user.service'; -import { FaqDialogComponent } from '../faq/dialog/faq-dialog.component'; -import { DmpInvitationDialogComponent } from '../dmp/invitation/dmp-invitation-dialog.component'; -import { StartNewDmpDialogComponent } from '../dmp/start-new-dmp-dialogue/start-new-dmp-dialog.component'; -import { UserListingModel } from '@app/core/model/user/user-listing'; -import { Principal } from '@app/core/model/auth/principal'; -import { MatomoService } from '@app/core/services/matomo/matomo-service'; -import { HttpClient } from '@angular/common/http'; -import { SideNavService } from '@app/core/services/sidenav/side-nav.sevice'; -import { ConfigurationService } from '@app/core/services/configuration/configuration.service'; - -const availableLanguages: any[] = require('../../../assets/resources/language.json'); - @Component({ selector: 'app-navbar', templateUrl: './navbar.component.html', @@ -36,8 +31,7 @@ export class NavbarComponent extends BaseComponent implements OnInit { mobile_menu_visible: any = 0; private toggleButton: any; private sidebarVisible: boolean; - languages = availableLanguages; - language = this.languages[0]; + languages = []; currentRoute: string; selectedLanguage: string; private user: UserListingModel; @@ -60,6 +54,7 @@ export class NavbarComponent extends BaseComponent implements OnInit { super(); this.location = location; this.sidebarVisible = false; + this.languages = this.configurationService.availableLanguages; this.selectedLanguage = this.configurationService.defaultLanguage || 'en'; } @@ -266,7 +261,7 @@ export class NavbarComponent extends BaseComponent implements OnInit { this.sidebarToggled.emit(event); } - toggleMyNav(event){ + toggleMyNav(event) { this.sidenavService.toggle(); } diff --git a/dmp-frontend/src/app/ui/user-profile/user-profile-editor.model.ts b/dmp-frontend/src/app/ui/user-profile/user-profile-editor.model.ts index 39044b5f4..9f5ea71ac 100644 --- a/dmp-frontend/src/app/ui/user-profile/user-profile-editor.model.ts +++ b/dmp-frontend/src/app/ui/user-profile/user-profile-editor.model.ts @@ -2,7 +2,6 @@ import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms' import { RoleOrganizationType } from '@app/core/common/enum/role-organization-type'; import { OrganizationModel } from '@app/core/model/organisation/organization'; import { UserListingModel } from '@app/core/model/user/user-listing'; -const availableLanguages: any[] = require('../../../assets/resources/language.json'); export class UserProfileEditorModel { public id: String; @@ -25,7 +24,7 @@ export class UserProfileEditorModel { return this; } - buildForm(): FormGroup { + buildForm(availableLanguages: any[]): FormGroup { const formGroup = new FormBuilder().group({ id: new FormControl(this.id), name: new FormControl(this.name), diff --git a/dmp-frontend/src/app/ui/user-profile/user-profile.component.ts b/dmp-frontend/src/app/ui/user-profile/user-profile.component.ts index 8e361894f..accdd49d5 100644 --- a/dmp-frontend/src/app/ui/user-profile/user-profile.component.ts +++ b/dmp-frontend/src/app/ui/user-profile/user-profile.component.ts @@ -31,9 +31,7 @@ import { FormValidationErrorsDialogComponent } from '@common/forms/form-validati import { SnackBarNotificationLevel, UiNotificationService } from '@app/core/services/notification/ui-notification-service'; import { MatomoService } from '@app/core/services/matomo/matomo-service'; import { HttpClient } from '@angular/common/http'; -import {PopupNotificationDialogComponent} from "@app/library/notification/popup/popup-notification.component"; - -const availableLanguages: any[] = require('../../../assets/resources/language.json'); +import { PopupNotificationDialogComponent } from "@app/library/notification/popup/popup-notification.component"; @Component({ selector: 'app-user-profile', @@ -49,7 +47,7 @@ export class UserProfileComponent extends BaseComponent implements OnInit, OnDes cultures: Observable; timezones: Observable; editMode = false; - languages = availableLanguages; + languages = []; zenodoToken: string; zenodoEmail: String; roleOrganizationEnum = RoleOrganizationType; @@ -86,7 +84,10 @@ export class UserProfileComponent extends BaseComponent implements OnInit, OnDes private mergeEmailConfirmation: MergeEmailConfirmationService, private httpClient: HttpClient, private matomoService: MatomoService - ) { super(); } + ) { + super(); + this.languages = this.configurationService.availableLanguages; + } ngOnInit() { this.matomoService.trackPageView('User Profile'); @@ -101,7 +102,7 @@ export class UserProfileComponent extends BaseComponent implements OnInit, OnDes this.zenodoEmail = result['zenodoEmail']; this.userProfileEditorModel = new UserProfileEditorModel().fromModel(result); - this.formGroup = this.userProfileEditorModel.buildForm(); + this.formGroup = this.userProfileEditorModel.buildForm(this.configurationService.availableLanguages); // this.formGroup = new FormBuilder().group({ // language: new FormControl(result['language'] ? availableLanguages.filter(x => x.value === result['language']['value']).pop() : '', [Validators.required]), // timezone: new FormControl(result['timezone'], [Validators.required]), diff --git a/dmp-frontend/src/assets/config/config.json b/dmp-frontend/src/assets/config/config.json index 72c5d8a10..3b2190325 100644 --- a/dmp-frontend/src/assets/config/config.json +++ b/dmp-frontend/src/assets/config/config.json @@ -8,6 +8,48 @@ }, "defaultCulture": "en-US", "defaultLanguage": "en", + "availableLanguages": [ + { + "label": "GENERAL.LANGUAGES.ENGLISH", + "value": "en" + }, + { + "label": "GENERAL.LANGUAGES.GREEK", + "value": "gr" + }, + { + "label": "GENERAL.LANGUAGES.SPANISH", + "value": "es" + }, + { + "label": "GENERAL.LANGUAGES.GERMAN", + "value": "de" + }, + { + "label": "GENERAL.LANGUAGES.TURKISH", + "value": "tr" + }, + { + "label": "GENERAL.LANGUAGES.SLOVAK", + "value": "sk" + }, + { + "label": "GENERAL.LANGUAGES.SERBIAN", + "value": "sr" + }, + { + "label": "GENERAL.LANGUAGES.PORTUGUESE", + "value": "pt" + }, + { + "label": "GENERAL.LANGUAGES.CROATIAN", + "value": "hr" + }, + { + "label": "GENERAL.LANGUAGES.POLISH", + "value": "pl" + } + ], "loginProviders": { "enabled": [1, 2, 3, 4, 5, 6, 7, 8], "facebookConfiguration": { "clientId": "" }, diff --git a/dmp-frontend/src/assets/resources/language.json b/dmp-frontend/src/assets/resources/language.json deleted file mode 100644 index 38da65f22..000000000 --- a/dmp-frontend/src/assets/resources/language.json +++ /dev/null @@ -1,42 +0,0 @@ -[ - { - "label": "GENERAL.LANGUAGES.ENGLISH", - "value": "en" - }, - { - "label": "GENERAL.LANGUAGES.GREEK", - "value": "gr" - }, - { - "label": "GENERAL.LANGUAGES.SPANISH", - "value": "es" - }, - { - "label": "GENERAL.LANGUAGES.GERMAN", - "value": "de" - }, - { - "label": "GENERAL.LANGUAGES.TURKISH", - "value": "tr" - }, - { - "label": "GENERAL.LANGUAGES.SLOVAK", - "value": "sk" - }, - { - "label": "GENERAL.LANGUAGES.SERBIAN", - "value": "sr" - }, - { - "label": "GENERAL.LANGUAGES.PORTUGUESE", - "value": "pt" - }, - { - "label": "GENERAL.LANGUAGES.CROATIAN", - "value": "hr" - }, - { - "label": "GENERAL.LANGUAGES.POLISH", - "value": "pl" - } -]