From b5ff049414954df5cf1d3f3709592d66718f407e Mon Sep 17 00:00:00 2001 From: illfixit <66363651+illfixit@users.noreply.github.com> Date: Sun, 29 Sep 2024 17:03:39 +0200 Subject: [PATCH 1/4] fix title, translate with slot --- .../routes/connector-ui/connector-ui.component.ts | 7 ++++++- .../dashboard-page/dashboard-page.component.html | 2 +- .../translate-with-slot.component.ts | 14 ++++++++++++-- src/assets/i18n/en.json | 1 + 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/app/routes/connector-ui/connector-ui.component.ts b/src/app/routes/connector-ui/connector-ui.component.ts index 03dce9a6..fda4db6f 100644 --- a/src/app/routes/connector-ui/connector-ui.component.ts +++ b/src/app/routes/connector-ui/connector-ui.component.ts @@ -34,7 +34,12 @@ export class ConnectorUiComponent implements OnInit { ) { this.navItemGroups = this.navItemsBuilder.buildNavItemGroups(); this.translateService.setDefaultLang('en'); - this.translateService.use(localStorage.getItem('selectedLanguage') || 'en'); + let selectedLanguage = localStorage.getItem('selectedLanguage'); + if (!selectedLanguage) { + selectedLanguage = 'en'; + localStorage.setItem('selectedLanguage', selectedLanguage); + } + this.translateService.use(JSON.parse(selectedLanguage)); } ngOnInit() { diff --git a/src/app/routes/connector-ui/dashboard-page/dashboard-page/dashboard-page.component.html b/src/app/routes/connector-ui/dashboard-page/dashboard-page/dashboard-page.component.html index 4f1d3b30..1919707c 100644 --- a/src/app/routes/connector-ui/dashboard-page/dashboard-page/dashboard-page.component.html +++ b/src/app/routes/connector-ui/dashboard-page/dashboard-page/dashboard-page.component.html @@ -31,7 +31,7 @@
this.translationService.get(this.key)), diff --git a/src/assets/i18n/en.json b/src/assets/i18n/en.json index f22ea9d3..357a604d 100644 --- a/src/assets/i18n/en.json +++ b/src/assets/i18n/en.json @@ -312,6 +312,7 @@ "dashboard_page.trans_pro": "Transfer Processes", "dashboard_page.transfer": "Transfer History", "dashboard_page.your_assets": "Your Assets", + "dashboard_page.your_data_offers": "Your Data Offers", "dashboard_page.your_def": "Your Contract Definitions", "dashboard_page.your_pol": "Your Policies", "edit_asset_page.title": "Edit Asset", From 6e0f1e29ae4038f3ed9d305dc5a7744cd2786e68 Mon Sep 17 00:00:00 2001 From: illfixit <66363651+illfixit@users.noreply.github.com> Date: Wed, 2 Oct 2024 11:03:42 +0200 Subject: [PATCH 2/4] chore: switch to translationService stream --- .../translate-with-slot.component.ts | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/app/shared/common/translate-with-slot/translate-with-slot.component.ts b/src/app/shared/common/translate-with-slot/translate-with-slot.component.ts index b50c6a56..f84f543d 100644 --- a/src/app/shared/common/translate-with-slot/translate-with-slot.component.ts +++ b/src/app/shared/common/translate-with-slot/translate-with-slot.component.ts @@ -1,4 +1,4 @@ -import {Component, Input, OnChanges, OnDestroy, OnInit} from '@angular/core'; +import {Component, Input, OnChanges, OnDestroy} from '@angular/core'; import {Subject, switchMap} from 'rxjs'; import {takeUntil} from 'rxjs/operators'; import {TranslateService} from '@ngx-translate/core'; @@ -8,9 +8,7 @@ import {SimpleChangesTyped} from '../../../core/utils/angular-utils'; selector: 'translate-with-slot', templateUrl: './translate-with-slot.component.html', }) -export class TranslateWithSlotComponent - implements OnInit, OnChanges, OnDestroy -{ +export class TranslateWithSlotComponent implements OnChanges, OnDestroy { @Input() key!: string; @@ -27,14 +25,10 @@ export class TranslateWithSlotComponent this.splitText(); } - ngOnInit() { - this.splitText(); - } - splitText() { this.key$ .pipe( - switchMap(() => this.translationService.get(this.key)), + switchMap(() => this.translationService.stream(this.key)), takeUntil(this.ngOnDestroy$), ) .subscribe((text) => { From c298c503db01cc5fbaa70a1c941b7efbc2f02bfc Mon Sep 17 00:00:00 2001 From: illfixit <66363651+illfixit@users.noreply.github.com> Date: Wed, 2 Oct 2024 11:30:38 +0200 Subject: [PATCH 3/4] chore: refactor selectedLanguage --- src/app/core/utils/i18n-utils.ts | 12 +++++++++++ src/app/core/utils/local-storage-utils.ts | 7 ++++++- .../connector-ui/connector-ui.component.ts | 15 ++++++++------ .../language-selector.component.ts | 20 ++++++++----------- 4 files changed, 35 insertions(+), 19 deletions(-) create mode 100644 src/app/core/utils/i18n-utils.ts diff --git a/src/app/core/utils/i18n-utils.ts b/src/app/core/utils/i18n-utils.ts new file mode 100644 index 00000000..6cf6899c --- /dev/null +++ b/src/app/core/utils/i18n-utils.ts @@ -0,0 +1,12 @@ +export interface AvailableLanguage { + code: string; + name: string; +} + +export const supportedLanguages: AvailableLanguage[] = [ + {code: 'en', name: 'English'}, + {code: 'de', name: 'Deutsch'}, +]; + +export const isLanguageSupported = (value: unknown): value is string => + supportedLanguages.map((it) => it.code).includes(value as string); diff --git a/src/app/core/utils/local-storage-utils.ts b/src/app/core/utils/local-storage-utils.ts index 0a310c4e..ab07b725 100644 --- a/src/app/core/utils/local-storage-utils.ts +++ b/src/app/core/utils/local-storage-utils.ts @@ -19,7 +19,12 @@ export class LocalStorageUtils { const storedItem = localStorage.getItem(key); try { - return storedItem == null ? defaultValue : JSON.parse(storedItem); + if (storedItem == null) { + this.saveData(key, defaultValue); + return defaultValue; + } else { + return JSON.parse(storedItem); + } } catch (e) { console.warn('Error parsing local storage value', key, storedItem); return defaultValue; diff --git a/src/app/routes/connector-ui/connector-ui.component.ts b/src/app/routes/connector-ui/connector-ui.component.ts index fda4db6f..80952b8e 100644 --- a/src/app/routes/connector-ui/connector-ui.component.ts +++ b/src/app/routes/connector-ui/connector-ui.component.ts @@ -6,6 +6,8 @@ import {map, shareReplay} from 'rxjs/operators'; import {TranslateService} from '@ngx-translate/core'; import {NavItemGroup} from 'src/app/core/services/models/nav-item-group'; import {NavItemsBuilder} from 'src/app/core/services/nav-items-builder'; +import {isLanguageSupported} from 'src/app/core/utils/i18n-utils'; +import {LocalStoredValue} from 'src/app/core/utils/local-stored-value'; import {APP_CONFIG, AppConfig} from '../../core/config/app-config'; import {LoginPollingService} from '../../core/services/login-polling.service'; @@ -24,6 +26,12 @@ export class ConnectorUiComponent implements OnInit { navItemGroups: NavItemGroup[] = []; + selectedLanguage = new LocalStoredValue( + 'en', + 'selectedLanguage', + isLanguageSupported, + ); + constructor( @Inject(APP_CONFIG) public config: AppConfig, public titleService: Title, @@ -34,12 +42,7 @@ export class ConnectorUiComponent implements OnInit { ) { this.navItemGroups = this.navItemsBuilder.buildNavItemGroups(); this.translateService.setDefaultLang('en'); - let selectedLanguage = localStorage.getItem('selectedLanguage'); - if (!selectedLanguage) { - selectedLanguage = 'en'; - localStorage.setItem('selectedLanguage', selectedLanguage); - } - this.translateService.use(JSON.parse(selectedLanguage)); + this.translateService.use(this.selectedLanguage.value); } ngOnInit() { diff --git a/src/app/shared/common/language-selector/language-selector.component.ts b/src/app/shared/common/language-selector/language-selector.component.ts index fbb69771..eb2da2ad 100644 --- a/src/app/shared/common/language-selector/language-selector.component.ts +++ b/src/app/shared/common/language-selector/language-selector.component.ts @@ -1,29 +1,25 @@ import {Component, OnInit} from '@angular/core'; import {TranslateService} from '@ngx-translate/core'; +import { + AvailableLanguage, + isLanguageSupported, + supportedLanguages, +} from 'src/app/core/utils/i18n-utils'; import {LocalStoredValue} from '../../../core/utils/local-stored-value'; -interface AvailableLanguage { - code: string; - name: string; -} - @Component({ selector: 'app-language-selector', templateUrl: './language-selector.component.html', }) export class LanguageSelectorComponent implements OnInit { - supportedLanguages: AvailableLanguage[] = [ - {code: 'en', name: 'English'}, - {code: 'de', name: 'Deutsch'}, - ]; - selectedLanguage = new LocalStoredValue( 'en', 'selectedLanguage', - (value): value is string => - this.supportedLanguages.map((it) => it.code).includes(value as string), + isLanguageSupported, ); + supportedLanguages = supportedLanguages; + constructor(private translateService: TranslateService) {} ngOnInit(): void { From 1cf6bc52619d43156c253fa3764d428f6a448312 Mon Sep 17 00:00:00 2001 From: Ilia Orlov <66363651+illfixit@users.noreply.github.com> Date: Fri, 4 Oct 2024 10:51:37 +0200 Subject: [PATCH 4/4] . --- src/app/core/utils/local-storage-utils.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/app/core/utils/local-storage-utils.ts b/src/app/core/utils/local-storage-utils.ts index ab07b725..0a310c4e 100644 --- a/src/app/core/utils/local-storage-utils.ts +++ b/src/app/core/utils/local-storage-utils.ts @@ -19,12 +19,7 @@ export class LocalStorageUtils { const storedItem = localStorage.getItem(key); try { - if (storedItem == null) { - this.saveData(key, defaultValue); - return defaultValue; - } else { - return JSON.parse(storedItem); - } + return storedItem == null ? defaultValue : JSON.parse(storedItem); } catch (e) { console.warn('Error parsing local storage value', key, storedItem); return defaultValue;