Browse Source

Merge pull request #24589 from abpframework/issue-24402

feat(core): use environment defaultResourceName as fallback for localization - Issue 24402
pull/24664/head
oykuermann 9 months ago
committed by GitHub
parent
commit
527895f963
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 2
      docs/en/framework/ui/angular/localization.md
  2. 30
      npm/ng-packs/packages/core/src/lib/services/config-state.service.ts

2
docs/en/framework/ui/angular/localization.md

@ -12,7 +12,7 @@ Before exploring _the localization pipe_ and _the localization service_, you sho
The localization key format consists of two sections which are **Resource Name** and **Key**.
`ResourceName::Key`
> If you do not specify the resource name, the `defaultResourceName` which is declared in `environment.ts` will be considered as default.
> If you do not specify the resource name, the `defaultResourceName` will be used. The value is first retrieved from the backend API response. If the backend does not provide a `defaultResourceName`, the value declared in `environment.ts` will be used as a fallback.
```ts
const environment = {

30
npm/ng-packs/packages/core/src/lib/services/config-state.service.ts

@ -10,6 +10,7 @@ import {
} from '../proxy/volo/abp/asp-net-core/mvc/application-configurations/models';
import { INCUDE_LOCALIZATION_RESOURCES_TOKEN } from '../tokens/include-localization-resources.token';
import { InternalStore } from '../utils/internal-store-utils';
import { EnvironmentService } from './environment.service';
@Injectable({
providedIn: 'root',
@ -17,6 +18,7 @@ import { InternalStore } from '../utils/internal-store-utils';
export class ConfigStateService {
private abpConfigService = inject(AbpApplicationConfigurationService);
private abpApplicationLocalizationService = inject(AbpApplicationLocalizationService);
private environmentService = inject(EnvironmentService);
private readonly includeLocalizationResources = inject(INCUDE_LOCALIZATION_RESOURCES_TOKEN, { optional: true });
private updateSubject = new Subject<void>();
@ -59,7 +61,18 @@ export class ConfigStateService {
this.uiCultureFromAuthCodeFlow ?? appState.localization.currentCulture.cultureName;
return this.getlocalizationResource(cultureName).pipe(
map(result => ({ ...appState, localization: { ...appState.localization, ...result } })),
map(result => {
const envLocalization = this.environmentService.getEnvironment()?.localization;
return {
...appState,
localization: {
...appState.localization,
...result,
defaultResourceName:
appState.localization?.defaultResourceName ?? envLocalization?.defaultResourceName,
},
};
}),
tap(() => (this.uiCultureFromAuthCodeFlow = undefined)),
);
}
@ -83,9 +96,18 @@ export class ConfigStateService {
return this.getlocalizationResource(lang)
.pipe(
tap(result =>
this.store.patch({ localization: { ...this.store.state.localization, ...result } }),
),
tap(result => {
const envLocalization = this.environmentService.getEnvironment()?.localization;
this.store.patch({
localization: {
...this.store.state.localization,
...result,
defaultResourceName:
this.store.state.localization?.defaultResourceName ??
envLocalization?.defaultResourceName,
},
});
}),
)
.pipe(map(() => null));
}

Loading…
Cancel
Save