Browse Source

Merge pull request #14562 from abpframework/issue/13946v2

getting language resources sepereated
pull/14561/head
Muhammed Altuğ 3 years ago
committed by GitHub
parent
commit
01dd9ed1cb
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      npm/ng-packs/packages/core/src/lib/core.module.ts
  2. 8
      npm/ng-packs/packages/core/src/lib/providers/include-localization-resources.provider.ts
  3. 1
      npm/ng-packs/packages/core/src/lib/providers/index.ts
  4. 38
      npm/ng-packs/packages/core/src/lib/services/config-state.service.ts
  5. 4
      npm/ng-packs/packages/core/src/lib/services/localization.service.ts
  6. 3
      npm/ng-packs/packages/core/src/lib/tokens/include-localization-resources.token.ts
  7. 1
      npm/ng-packs/packages/core/src/lib/tokens/index.ts

2
npm/ng-packs/packages/core/src/lib/core.module.ts

@ -38,6 +38,7 @@ import { ShortDateTimePipe } from './pipes/short-date-time.pipe';
import { ShortTimePipe } from './pipes/short-time.pipe'; import { ShortTimePipe } from './pipes/short-time.pipe';
import { ShortDatePipe } from './pipes/short-date.pipe'; import { ShortDatePipe } from './pipes/short-date.pipe';
import { TimeoutLimitedOAuthService } from './services/timeout-limited-oauth.service'; import { TimeoutLimitedOAuthService } from './services/timeout-limited-oauth.service';
import { IncludeLocalizationResourcesProvider } from './providers/include-localization-resources.provider';
export function storageFactory(): OAuthStorage { export function storageFactory(): OAuthStorage {
return oAuthStorage; return oAuthStorage;
@ -193,6 +194,7 @@ export class CoreModule {
useValue: localizationContributor(options.localizations), useValue: localizationContributor(options.localizations),
deps: [LocalizationService], deps: [LocalizationService],
}, },
IncludeLocalizationResourcesProvider
], ],
}; };
} }

8
npm/ng-packs/packages/core/src/lib/providers/include-localization-resources.provider.ts

@ -0,0 +1,8 @@
import { Provider } from "@angular/core";
import { INCUDE_LOCALIZATION_RESOURCES_TOKEN } from "../tokens/include-localization-resources.token";
export const IncludeLocalizationResourcesProvider: Provider = {
provide: INCUDE_LOCALIZATION_RESOURCES_TOKEN,
useValue: false,
};

1
npm/ng-packs/packages/core/src/lib/providers/index.ts

@ -1,2 +1,3 @@
export * from './cookie-language.provider'; export * from './cookie-language.provider';
export * from './locale.provider'; export * from './locale.provider';
export * from './include-localization-resources.provider';

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

@ -1,12 +1,13 @@
import { Injectable } from '@angular/core'; import { Inject, Injectable } from '@angular/core';
import { Observable, Subject, of } from 'rxjs'; import { Observable, Subject, of } from 'rxjs';
import { map, switchMap, take } from 'rxjs/operators'; import { map, switchMap, take, tap } from 'rxjs/operators';
import { AbpApplicationConfigurationService } from '../proxy/volo/abp/asp-net-core/mvc/application-configurations/abp-application-configuration.service'; import { AbpApplicationConfigurationService } from '../proxy/volo/abp/asp-net-core/mvc/application-configurations/abp-application-configuration.service';
import { AbpApplicationLocalizationService } from '../proxy/volo/abp/asp-net-core/mvc/application-configurations/abp-application-localization.service'; import { AbpApplicationLocalizationService } from '../proxy/volo/abp/asp-net-core/mvc/application-configurations/abp-application-localization.service';
import { import {
ApplicationConfigurationDto, ApplicationConfigurationDto,
ApplicationGlobalFeatureConfigurationDto, ApplicationGlobalFeatureConfigurationDto,
} from '../proxy/volo/abp/asp-net-core/mvc/application-configurations/models'; } 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 { InternalStore } from '../utils/internal-store-utils';
@Injectable({ @Injectable({
@ -14,7 +15,6 @@ import { InternalStore } from '../utils/internal-store-utils';
}) })
export class ConfigStateService { export class ConfigStateService {
private readonly store = new InternalStore({} as ApplicationConfigurationDto); private readonly store = new InternalStore({} as ApplicationConfigurationDto);
private includeLocalizationResources = false;
get createOnUpdateStream() { get createOnUpdateStream() {
return this.store.sliceUpdate; return this.store.sliceUpdate;
@ -25,6 +25,8 @@ export class ConfigStateService {
constructor( constructor(
private abpConfigService: AbpApplicationConfigurationService, private abpConfigService: AbpApplicationConfigurationService,
private abpApplicationLocalizationService: AbpApplicationLocalizationService, private abpApplicationLocalizationService: AbpApplicationLocalizationService,
@Inject(INCUDE_LOCALIZATION_RESOURCES_TOKEN)
private readonly includeLocalizationResources: boolean,
) { ) {
this.initUpdateStream(); this.initUpdateStream();
} }
@ -45,20 +47,36 @@ export class ConfigStateService {
private getLocalizationAndCombineWithAppState( private getLocalizationAndCombineWithAppState(
appState: ApplicationConfigurationDto, appState: ApplicationConfigurationDto,
): Observable<ApplicationConfigurationDto> { ): Observable<ApplicationConfigurationDto> {
return this.abpApplicationLocalizationService return this.getlocalizationResource(appState.localization.currentCulture.cultureName).pipe(
.get({ cultureName: appState.localization.currentCulture.name, onlyDynamics: false }) map(result => ({ ...appState, localization: { ...appState.localization, ...result } })),
.pipe( );
switchMap(result =>
of({ ...appState, localization: { ...appState.localization, ...result } }),
),
);
} }
private getlocalizationResource(cultureName: string) {
return this.abpApplicationLocalizationService.get({
cultureName: cultureName,
onlyDynamics: false,
});
}
refreshAppState() { refreshAppState() {
this.updateSubject.next(); this.updateSubject.next();
return this.createOnUpdateStream(state => state).pipe(take(1)); return this.createOnUpdateStream(state => state).pipe(take(1));
} }
refreshLocalization(lang: string): Observable<null> {
if (this.includeLocalizationResources) {
return this.refreshAppState().pipe(map(() => null));
} else {
return this.getlocalizationResource(lang)
.pipe(
tap(result =>
this.store.patch({ localization: { ...this.store.state.localization, ...result } }),
),
)
.pipe(map(() => null));
}
}
getOne$(key: string) { getOne$(key: string) {
return this.store.sliceState(state => state[key]); return this.store.sliceState(state => state[key]);
} }

4
npm/ng-packs/packages/core/src/lib/services/localization.service.ts

@ -1,6 +1,6 @@
import { registerLocaleData } from '@angular/common'; import { registerLocaleData } from '@angular/common';
import { Injectable, Injector, isDevMode, Optional, SkipSelf } from '@angular/core'; import { Injectable, Injector, isDevMode, Optional, SkipSelf } from '@angular/core';
import { BehaviorSubject, combineLatest, from, Observable, Subject } from 'rxjs'; import { BehaviorSubject, combineLatest, from, Observable, of, Subject } from 'rxjs';
import { filter, map, mapTo, switchMap } from 'rxjs/operators'; import { filter, map, mapTo, switchMap } from 'rxjs/operators';
import { ABP } from '../models/common'; import { ABP } from '../models/common';
import { LocalizationWithDefault } from '../models/localization'; import { LocalizationWithDefault } from '../models/localization';
@ -133,7 +133,7 @@ export class LocalizationService {
filter( filter(
lang => this.configState.getDeep('localization.currentCulture.cultureName') !== lang, lang => this.configState.getDeep('localization.currentCulture.cultureName') !== lang,
), ),
switchMap(lang => this.configState.refreshAppState().pipe(mapTo(lang))), switchMap(lang => this.configState.refreshLocalization(lang).pipe(map(()=> lang))),
switchMap(lang => from(this.registerLocale(lang).then(() => lang))), switchMap(lang => from(this.registerLocale(lang).then(() => lang))),
) )
.subscribe(lang => this._languageChange$.next(lang)); .subscribe(lang => this._languageChange$.next(lang));

3
npm/ng-packs/packages/core/src/lib/tokens/include-localization-resources.token.ts

@ -0,0 +1,3 @@
import { InjectionToken } from "@angular/core";
export const INCUDE_LOCALIZATION_RESOURCES_TOKEN = new InjectionToken<boolean>('INCUDE_LOCALIZATION_RESOURCES_TOKEN');

1
npm/ng-packs/packages/core/src/lib/tokens/index.ts

@ -6,3 +6,4 @@ export * from './lodaer-delay.token';
export * from './manage-profile.token'; export * from './manage-profile.token';
export * from './options.token'; export * from './options.token';
export * from './tenant-key.token'; export * from './tenant-key.token';
export * from './include-localization-resources.token';
Loading…
Cancel
Save