Browse Source

Merge pull request #5403 from abpframework/feat/5402

feat: enable retrieving resource from LocalizationService
pull/5406/head
Bunyamin Coskuner 6 years ago
committed by GitHub
parent
commit
e76f615fe4
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      npm/ng-packs/packages/core/src/lib/services/config-state.service.ts
  2. 4
      npm/ng-packs/packages/core/src/lib/services/localization.service.ts
  3. 10
      npm/ng-packs/packages/core/src/lib/states/config.state.ts

4
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)); return this.store.selectSnapshot(ConfigState.getLocalization(...args));
} }
getLocalizationResource(...args: Parameters<typeof ConfigState.getLocalizationResource>) {
return this.store.selectSnapshot(ConfigState.getLocalizationResource(...args));
}
dispatchGetAppConfiguration() { dispatchGetAppConfiguration() {
return this.store.dispatch(new GetAppConfiguration()); return this.store.dispatch(new GetAppConfiguration());
} }

4
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)); 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. * Returns localized text with the given interpolation parameters in current language.
* @param key Localization key to replace with localized text * @param key Localization key to replace with localized text

10
npm/ng-packs/packages/core/src/lib/states/config.state.ts

@ -128,6 +128,16 @@ export class ConfigState {
return selector; 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( static getLocalization(
key: string | Config.LocalizationWithDefault, key: string | Config.LocalizationWithDefault,
...interpolateParams: string[] ...interpolateParams: string[]

Loading…
Cancel
Save