Browse Source

getting language resources sepereated

pull/14562/head
Mahmut Gundogdu 3 years ago
parent
commit
8a4e2f3316
  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. 33
      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 { ShortDatePipe } from './pipes/short-date.pipe';
import { TimeoutLimitedOAuthService } from './services/timeout-limited-oauth.service';
import { IncludeLocalizationResourcesProvider } from './providers/include-localization-resources.provider';
export function storageFactory(): OAuthStorage {
return oAuthStorage;
@ -193,6 +194,7 @@ export class CoreModule {
useValue: localizationContributor(options.localizations),
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 './locale.provider';
export * from './include-localization-resources.provider';

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

@ -1,4 +1,4 @@
import { Injectable } from '@angular/core';
import { Inject, Injectable } from '@angular/core';
import { Observable, Subject, of } from 'rxjs';
import { map, switchMap, take } from 'rxjs/operators';
import { AbpApplicationConfigurationService } from '../proxy/volo/abp/asp-net-core/mvc/application-configurations/abp-application-configuration.service';
@ -7,6 +7,7 @@ import {
ApplicationConfigurationDto,
ApplicationGlobalFeatureConfigurationDto,
} 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';
@Injectable({
@ -14,8 +15,7 @@ import { InternalStore } from '../utils/internal-store-utils';
})
export class ConfigStateService {
private readonly store = new InternalStore({} as ApplicationConfigurationDto);
private includeLocalizationResources = false;
get createOnUpdateStream() {
return this.store.sliceUpdate;
}
@ -25,6 +25,7 @@ export class ConfigStateService {
constructor(
private abpConfigService: AbpApplicationConfigurationService,
private abpApplicationLocalizationService: AbpApplicationLocalizationService,
@Inject(INCUDE_LOCALIZATION_RESOURCES_TOKEN) private readonly includeLocalizationResources: boolean,
) {
this.initUpdateStream();
}
@ -36,7 +37,7 @@ export class ConfigStateService {
this.abpConfigService.get({
includeLocalizationResources: this.includeLocalizationResources,
}),
),
)
)
.pipe(switchMap(appState => this.getLocalizationAndCombineWithAppState(appState)))
.subscribe(res => this.store.set(res));
@ -45,20 +46,36 @@ export class ConfigStateService {
private getLocalizationAndCombineWithAppState(
appState: ApplicationConfigurationDto,
): Observable<ApplicationConfigurationDto> {
return this.abpApplicationLocalizationService
.get({ cultureName: appState.localization.currentCulture.name, onlyDynamics: false })
return this.getlocalizationResource(appState.localization.currentCulture.cultureName)
.pipe(
switchMap(result =>
of({ ...appState, localization: { ...appState.localization, ...result } }),
map(result =>({ ...appState, localization: { ...appState.localization, ...result } }),
),
);
}
private getlocalizationResource(cultureName:string){
return this.abpApplicationLocalizationService
.get({ cultureName: cultureName, onlyDynamics: false })
}
refreshAppState() {
this.updateSubject.next();
return this.createOnUpdateStream(state => state).pipe(take(1));
}
refreshLocalization(lang:string) {
if (this.includeLocalizationResources) {
return this.refreshAppState();
} else {
return this.getlocalizationResource(lang)
.pipe(
switchMap(result => {
this.store.patch({ localization: { ...this.store.state.localization, ...result } });
return of(null);
}),
);
}
}
getOne$(key: string) {
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 { 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 { ABP } from '../models/common';
import { LocalizationWithDefault } from '../models/localization';
@ -133,7 +133,7 @@ export class LocalizationService {
filter(
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))),
)
.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 './options.token';
export * from './tenant-key.token';
export * from './include-localization-resources.token';
Loading…
Cancel
Save