From 6041f31022180154b621eda958ef3b98cf4952d4 Mon Sep 17 00:00:00 2001 From: bnymncoskuner Date: Tue, 15 Sep 2020 10:35:41 +0300 Subject: [PATCH 1/3] feat: enable retrieving resource from LocalizationService --- .../packages/core/src/lib/services/localization.service.ts | 4 ++++ npm/ng-packs/packages/core/src/lib/states/config.state.ts | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/npm/ng-packs/packages/core/src/lib/services/localization.service.ts b/npm/ng-packs/packages/core/src/lib/services/localization.service.ts index 5b98afe0c37..dd64bd27eca 100644 --- a/npm/ng-packs/packages/core/src/lib/services/localization.service.ts +++ b/npm/ng-packs/packages/core/src/lib/services/localization.service.ts @@ -70,6 +70,10 @@ export class LocalizationService { return this.store.select(ConfigState.getLocalization(key, ...interpolateParams)); } + getResource(resourceName: string) { + return this.store.select(ConfigState.getLocalizationResource(resourceName)); + } + /** * Returns localized text with the given interpolation parameters in current language. * @param key Localization key to replace with localized text diff --git a/npm/ng-packs/packages/core/src/lib/states/config.state.ts b/npm/ng-packs/packages/core/src/lib/states/config.state.ts index ec9ccd67492..1fd67c71f88 100644 --- a/npm/ng-packs/packages/core/src/lib/states/config.state.ts +++ b/npm/ng-packs/packages/core/src/lib/states/config.state.ts @@ -128,6 +128,12 @@ export class ConfigState { return selector; } + static getLocalizationResource(resourceName: string) { + return createSelector([ConfigState], (state: Config.State) => { + return state.localization.values[resourceName]; + }); + } + static getLocalization( key: string | Config.LocalizationWithDefault, ...interpolateParams: string[] From 1fd0ba5c655390596eb6ec2d383e361978b699f9 Mon Sep 17 00:00:00 2001 From: bnymncoskuner Date: Tue, 15 Sep 2020 10:51:09 +0300 Subject: [PATCH 2/3] fix: build error for localization resource --- npm/ng-packs/packages/core/src/lib/states/config.state.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/npm/ng-packs/packages/core/src/lib/states/config.state.ts b/npm/ng-packs/packages/core/src/lib/states/config.state.ts index 1fd67c71f88..86399814566 100644 --- a/npm/ng-packs/packages/core/src/lib/states/config.state.ts +++ b/npm/ng-packs/packages/core/src/lib/states/config.state.ts @@ -129,9 +129,13 @@ export class ConfigState { } static getLocalizationResource(resourceName: string) { - return createSelector([ConfigState], (state: Config.State) => { + const selector = createSelector([ConfigState], (state: Config.State): { + [key: string]: string; + } => { return state.localization.values[resourceName]; }); + + return selector; } static getLocalization( From a177107c0e035f5bfe0ef6a06250836d91e1be27 Mon Sep 17 00:00:00 2001 From: bnymncoskuner Date: Tue, 15 Sep 2020 11:37:06 +0300 Subject: [PATCH 3/3] test: fix test by adding same method to ConfigStateService --- .../packages/core/src/lib/services/config-state.service.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/npm/ng-packs/packages/core/src/lib/services/config-state.service.ts b/npm/ng-packs/packages/core/src/lib/services/config-state.service.ts index 027c284f525..dd7abf929ef 100644 --- a/npm/ng-packs/packages/core/src/lib/services/config-state.service.ts +++ b/npm/ng-packs/packages/core/src/lib/services/config-state.service.ts @@ -49,6 +49,10 @@ export class ConfigStateService { return this.store.selectSnapshot(ConfigState.getLocalization(...args)); } + getLocalizationResource(...args: Parameters) { + return this.store.selectSnapshot(ConfigState.getLocalizationResource(...args)); + } + dispatchGetAppConfiguration() { return this.store.dispatch(new GetAppConfiguration()); }