From b018dd42db2f394424ca2283cc077a090c6d7a1f Mon Sep 17 00:00:00 2001 From: Diamantis Tziotzios Date: Tue, 11 Oct 2022 18:52:08 +0300 Subject: [PATCH] fixed default language support --- dmp-frontend/src/app/app.component.ts | 4 ++-- .../core/services/configuration/configuration.service.ts | 6 ++++++ .../src/app/core/services/language/language.service.ts | 3 ++- dmp-frontend/src/app/ui/navbar/navbar.component.ts | 7 +++++-- dmp-frontend/src/assets/config/config.json | 1 + 5 files changed, 16 insertions(+), 5 deletions(-) diff --git a/dmp-frontend/src/app/app.component.ts b/dmp-frontend/src/app/app.component.ts index e514f7614..8eb8b023f 100644 --- a/dmp-frontend/src/app/app.component.ts +++ b/dmp-frontend/src/app/app.component.ts @@ -224,9 +224,9 @@ export class AppComponent implements OnInit, AfterViewInit { // } initializeServices() { - this.translate.setDefaultLang('en'); + this.translate.setDefaultLang(this.configurationService.defaultLanguage || 'en'); this.authentication.current() && this.authentication.current().culture ? this.cultureService.cultureSelected(this.authentication.current().culture) : this.cultureService.cultureSelected(this.configurationService.defaultCulture); - this.authentication.current() && this.authentication.current().language ? this.language.changeLanguage(this.authentication.current().language) : this.language.changeLanguage('en'); + this.authentication.current() && this.authentication.current().language ? this.language.changeLanguage(this.authentication.current().language) : (this.configurationService.defaultLanguage || 'en'); } toggleNavbar(event) { 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 6602ccfa1..9b92ad064 100644 --- a/dmp-frontend/src/app/core/services/configuration/configuration.service.ts +++ b/dmp-frontend/src/app/core/services/configuration/configuration.service.ts @@ -36,6 +36,11 @@ export class ConfigurationService extends BaseComponent { return this._defaultCulture; } + private _defaultLanguage: string; + get defaultLanguage(): string { + return this._defaultLanguage; + } + private _loginProviders: LoginProviders; get loginProviders(): LoginProviders { return this._loginProviders; @@ -126,6 +131,7 @@ export class ConfigurationService extends BaseComponent { this._app = config.App; this._helpService = HelpService.parseValue(config.HelpService); this._defaultCulture = config.defaultCulture; + this._defaultLanguage = config.defaultLanguage; 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 ad69aeebc..b37a36b20 100644 --- a/dmp-frontend/src/app/core/services/language/language.service.ts +++ b/dmp-frontend/src/app/core/services/language/language.service.ts @@ -11,7 +11,7 @@ const availableLanguages: any[] = require('../../../../assets/resources/language @Injectable() export class LanguageService { - private currentLanguage: string = 'en'; + private currentLanguage: string; private languageUrl : string; constructor( @@ -21,6 +21,7 @@ export class LanguageService { private configurationService: ConfigurationService ) { this.languageUrl = `${configurationService.server}language`; + this.currentLanguage = this.configurationService.defaultLanguage || 'en'; } public changeLanguage(lang: string) { diff --git a/dmp-frontend/src/app/ui/navbar/navbar.component.ts b/dmp-frontend/src/app/ui/navbar/navbar.component.ts index aeccb0abb..8b1185d4e 100644 --- a/dmp-frontend/src/app/ui/navbar/navbar.component.ts +++ b/dmp-frontend/src/app/ui/navbar/navbar.component.ts @@ -20,6 +20,7 @@ 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'); @@ -38,7 +39,7 @@ export class NavbarComponent extends BaseComponent implements OnInit { languages = availableLanguages; language = this.languages[0]; currentRoute: string; - selectedLanguage = 'en'; + selectedLanguage: string; private user: UserListingModel; @Output() sidebarToggled: EventEmitter = new EventEmitter(); @ViewChild(MatMenuTrigger) trigger: MatMenuTrigger; @@ -53,11 +54,13 @@ export class NavbarComponent extends BaseComponent implements OnInit { public userService: UserService, private httpClient: HttpClient, private matomoService: MatomoService, - private sidenavService: SideNavService + private sidenavService: SideNavService, + private configurationService: ConfigurationService ) { super(); this.location = location; this.sidebarVisible = false; + this.selectedLanguage = this.configurationService.defaultLanguage || 'en'; } ngOnInit() { diff --git a/dmp-frontend/src/assets/config/config.json b/dmp-frontend/src/assets/config/config.json index e37401e1e..7b0bbad3d 100644 --- a/dmp-frontend/src/assets/config/config.json +++ b/dmp-frontend/src/assets/config/config.json @@ -7,6 +7,7 @@ "Url": "localhost:5000/" }, "defaultCulture": "en-US", + "defaultLanguage": "en", "loginProviders": { "enabled": [1, 2, 3, 4, 5, 6, 7, 8], "facebookConfiguration": { "clientId": "" },