configurable list of languages

This commit is contained in:
Diamantis Tziotzios 2023-02-11 14:38:13 +02:00
parent 554eb96824
commit 72daadee7e
9 changed files with 77 additions and 76 deletions

View File

@ -30,7 +30,6 @@
"scripts": [
"node_modules/cookieconsent/build/cookieconsent.min.js",
"node_modules/tinymce/tinymce.min.js"
],
"vendorChunk": true,
"extractLicenses": false,

View File

@ -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;

View File

@ -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);
}

View File

@ -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<any> = 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)

View File

@ -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';
}

View File

@ -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),

View File

@ -33,8 +33,6 @@ 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');
@Component({
selector: 'app-user-profile',
templateUrl: './user-profile.component.html',
@ -49,7 +47,7 @@ export class UserProfileComponent extends BaseComponent implements OnInit, OnDes
cultures: Observable<CultureInfo[]>;
timezones: Observable<any[]>;
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]),

View File

@ -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": "" },

View File

@ -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"
}
]