Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enable retrieving resource from LocalizationService #5403

Merged
merged 3 commits into from
Sep 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ export class ConfigStateService {
return this.store.selectSnapshot(ConfigState.getLocalization(...args));
}

getLocalizationResource(...args: Parameters<typeof ConfigState.getLocalizationResource>) {
return this.store.selectSnapshot(ConfigState.getLocalizationResource(...args));
}

dispatchGetAppConfiguration() {
return this.store.dispatch(new GetAppConfiguration());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions npm/ng-packs/packages/core/src/lib/states/config.state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,16 @@ export class ConfigState {
return selector;
}

static getLocalizationResource(resourceName: string) {
const selector = createSelector([ConfigState], (state: Config.State): {
[key: string]: string;
} => {
return state.localization.values[resourceName];
});

return selector;
}

static getLocalization(
key: string | Config.LocalizationWithDefault,
...interpolateParams: string[]
Expand Down