mirror of https://github.com/abpframework/abp.git
committed by
GitHub
85 changed files with 354 additions and 140 deletions
|
After Width: | Height: | Size: 32 KiB |
|
After Width: | Height: | Size: 26 KiB |
@ -0,0 +1,88 @@ |
|||
# How to override localization strings of depending modules |
|||
|
|||
## Source Code |
|||
|
|||
You can find the source of the example solution used in this article [here](https://github.com/abpframework/abp-samples/tree/master/DocumentationSamples/ExtendLocalizationResource). |
|||
|
|||
## Getting Started |
|||
|
|||
This example is based on the following document |
|||
https://docs.abp.io/en/abp/latest/Localization#extending-existing-resource |
|||
|
|||
We will change the default `DisplayName:Abp.Timing.Timezone` and `Description:Abp.Timing.Timezone` of [`AbpTimingResource`](https://github.com/abpframework/abp/blob/dev/framework/src/Volo.Abp.Timing/Volo/Abp/Timing/Localization/AbpTimingResource.cs) and add localized text in [Russian language(`ru`)](https://github.com/abpframework/abp/blob/dev/framework/src/Volo.Abp.Timing/Volo/Abp/Timing/Localization/en.json). |
|||
|
|||
I created the `AbpTiming` folder in the `Localization` directory of the `ExtendLocalizationResource.Domain.Shared` project. |
|||
|
|||
Create `en.json` and `ru.json` in its directory. |
|||
|
|||
`en.json` |
|||
```json |
|||
{ |
|||
"culture": "en", |
|||
"texts": { |
|||
"DisplayName:Abp.Timing.Timezone": "My Time zone", |
|||
"Description:Abp.Timing.Timezone": "My Application time zone" |
|||
} |
|||
} |
|||
``` |
|||
|
|||
`ru.json` |
|||
```json |
|||
{ |
|||
"culture": "ru", |
|||
"texts": { |
|||
"DisplayName:Abp.Timing.Timezone": "Часовой пояс", |
|||
"Description:Abp.Timing.Timezone": "Часовой пояс приложения" |
|||
} |
|||
} |
|||
``` |
|||
|
|||
 |
|||
|
|||
We have below content in `ExtendLocalizationResource.Domain.Shared.csproj` file, See [Virtual-File-System](https://docs.abp.io/en/abp/latest/Virtual-File-System#working-with-the-embedded-files) understand how it works. |
|||
|
|||
```xml |
|||
<ItemGroup> |
|||
<EmbeddedResource Include="Localization\ExtendLocalizationResource\*.json" /> |
|||
<Content Remove="Localization\ExtendLocalizationResource\*.json" /> |
|||
</ItemGroup> |
|||
|
|||
<ItemGroup> |
|||
<PackageReference Include="Microsoft.Extensions.FileProviders.Embedded" Version="5.0.*" /> |
|||
</ItemGroup> |
|||
``` |
|||
|
|||
Change the code of the `ConfigureServices` method in `ExtendLocalizationResourceDomainSharedModule`. |
|||
|
|||
```cs |
|||
Configure<AbpLocalizationOptions>(options => |
|||
{ |
|||
options.Resources |
|||
.Add<ExtendLocalizationResourceResource>("en") |
|||
.AddBaseTypes(typeof(AbpValidationResource)) |
|||
.AddVirtualJson("/Localization/ExtendLocalizationResource"); |
|||
|
|||
//add following code |
|||
options.Resources |
|||
.Get<AbpTimingResource>() |
|||
.AddVirtualJson("/Localization/AbpTiming"); |
|||
|
|||
options.DefaultResourceType = typeof(ExtendLocalizationResourceResource); |
|||
}); |
|||
``` |
|||
|
|||
Execute `ExtendLocalizationResource.DbMigrator` to migrate the database and run `ExtendLocalizationResource.Web`. |
|||
|
|||
We have changed the English localization text and added Russian localization. |
|||
|
|||
### Index page |
|||
|
|||
```cs |
|||
<p>@AbpTimingResource["DisplayName:Abp.Timing.Timezone"]</p> |
|||
@using(CultureHelper.Use("ru")) |
|||
{ |
|||
<p>@AbpTimingResource["DisplayName:Abp.Timing.Timezone"]</p> |
|||
} |
|||
``` |
|||
|
|||
 |
|||
@ -0,0 +1,39 @@ |
|||
import { ConfigStateService, featuresFactory, noop } from '@abp/ng.core'; |
|||
import { APP_INITIALIZER, inject, InjectionToken } from '@angular/core'; |
|||
import { Observable } from 'rxjs'; |
|||
import { map } from 'rxjs/operators'; |
|||
|
|||
export const SETTING_MANAGEMENT_FEATURES = new InjectionToken<Observable<{ enable: boolean }>>( |
|||
'SETTING_MANAGEMENT_FEATURES', |
|||
{ |
|||
providedIn: 'root', |
|||
factory: () => { |
|||
const configState = inject(ConfigStateService); |
|||
const featureKey = 'SettingManagement.Enable'; |
|||
const mapFn = features => ({ |
|||
enable: features[featureKey].toLowerCase() !== 'false', |
|||
}); |
|||
return featuresFactory(configState, [featureKey], mapFn); |
|||
}, |
|||
}, |
|||
); |
|||
|
|||
export const SETTING_MANAGEMENT_ROUTE_VISIBILITY = new InjectionToken<Observable<boolean>>( |
|||
'SETTING_MANAGEMENT_ROUTE_VISIBILITY', |
|||
{ |
|||
providedIn: 'root', |
|||
factory: () => { |
|||
const stream = inject(SETTING_MANAGEMENT_FEATURES); |
|||
return stream.pipe(map(features => features.enable)); |
|||
}, |
|||
}, |
|||
); |
|||
|
|||
export const SETTING_MANAGEMENT_FEATURES_PROVIDERS = [ |
|||
{ |
|||
provide: APP_INITIALIZER, |
|||
useFactory: noop, |
|||
deps: [SETTING_MANAGEMENT_ROUTE_VISIBILITY], |
|||
multi: true, |
|||
}, |
|||
]; |
|||
@ -1,2 +1,3 @@ |
|||
export * from './route.provider'; |
|||
export * from './setting-tab.provider'; |
|||
export * from './visible.provider'; |
|||
|
|||
@ -0,0 +1,30 @@ |
|||
import { APP_INITIALIZER, Injector } from '@angular/core'; |
|||
import { combineLatest } from 'rxjs'; |
|||
import { RoutesService } from '@abp/ng.core'; |
|||
import { SETTING_MANAGEMENT_HAS_SETTING } from './route.provider'; |
|||
import { SETTING_MANAGEMENT_ROUTE_VISIBILITY } from './features.token'; |
|||
import { eSettingManagementRouteNames } from '../enums'; |
|||
|
|||
export const SETTING_MANAGEMENT_VISIBLE_PROVIDERS = [ |
|||
{ |
|||
provide: APP_INITIALIZER, |
|||
useFactory: setSettingManagementVisibility, |
|||
deps: [Injector], |
|||
multi: true, |
|||
}, |
|||
]; |
|||
|
|||
export function setSettingManagementVisibility(injector: Injector) { |
|||
return () => { |
|||
const settingManagementHasSetting$ = injector.get(SETTING_MANAGEMENT_HAS_SETTING); |
|||
const isSettingManagementFeatureEnable$ = injector.get(SETTING_MANAGEMENT_ROUTE_VISIBILITY); |
|||
const routes = injector.get(RoutesService); |
|||
combineLatest([settingManagementHasSetting$, isSettingManagementFeatureEnable$]).subscribe( |
|||
([settingManagementHasSetting, isSettingManagementFeatureEnable]) => { |
|||
routes.patch(eSettingManagementRouteNames.Settings, { |
|||
invisible: !(settingManagementHasSetting && isSettingManagementFeatureEnable), |
|||
}); |
|||
}, |
|||
); |
|||
}; |
|||
} |
|||
Loading…
Reference in new issue