Browse Source

Use `AbpEnumLocalizer` replace `EnumHelper.GetLocalizedMemberName`

pull/19/head
Jadyn 2 years ago
parent
commit
8dc6f1e599
  1. 8
      samples/BookStore/src/BookStore.DbMigrator/BookStore.DbMigrator.csproj
  2. 10
      samples/BookStore/src/BookStore.DbMigrator/Properties/launchSettings.json
  3. 14
      samples/BookStore/src/BookStore.Domain.Shared/BookStoreModuleExtensionConfigurator.cs
  4. 7
      samples/BookStore/src/BookStore.Domain.Shared/Identity/IdentityUserType.cs
  5. 5
      samples/BookStore/src/BookStore.Domain.Shared/Localization/BookStore/en.json
  6. 17
      samples/BookStore/src/BookStore.Domain.Shared/Localization/BookStore/zh-Hans.json
  7. 4
      src/Lsw.Abp.AntDesignUI/AbpCrudPageBase.cs
  8. 28
      src/Lsw.Abp.AntDesignUI/Components/ObjectExtending/EnumHelper.cs
  9. 4
      src/Lsw.Abp.AntDesignUI/Components/ObjectExtending/ExtensionPropertyComponentBase.cs
  10. 2
      src/Lsw.Abp.AntDesignUI/Components/ObjectExtending/SelectExtensionProperty.razor.cs

8
samples/BookStore/src/BookStore.DbMigrator/BookStore.DbMigrator.csproj

@ -5,6 +5,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<UserSecretsId>BookStore-4681b4fd-151f-4221-84a4-929d86723e4c</UserSecretsId>
</PropertyGroup>
<ItemGroup>
@ -40,4 +41,11 @@
<None Remove="Logs\**" />
</ItemGroup>
<ItemGroup>
<None Update="Properties\launchSettings.json">
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
</Project>

10
samples/BookStore/src/BookStore.DbMigrator/Properties/launchSettings.json

@ -0,0 +1,10 @@
{
"profiles": {
"BookStore.DbMigrator": {
"commandName": "Project",
"environmentVariables": {
"DOTNET_ENVIRONMENT": "Development"
}
}
}
}

14
samples/BookStore/src/BookStore.Domain.Shared/BookStoreModuleExtensionConfigurator.cs

@ -1,4 +1,5 @@
using Volo.Abp.Identity;
using BookStore.Identity;
using Volo.Abp.Identity;
using Volo.Abp.ObjectExtending;
using Volo.Abp.Threading;
@ -66,5 +67,16 @@ public static class BookStoreModuleExtensionConfigurator
* See the documentation for more:
* https://docs.abp.io/en/abp/latest/Module-Entity-Extensions
*/
ObjectExtensionManager.Instance.Modules()
.ConfigureIdentity(identity => {
identity.ConfigureUser(user =>
{
user.AddOrUpdateProperty<IdentityUserType>("IdentityUserType", property =>
{
property.DefaultValue = IdentityUserType.Normal;
});
});
});
}
}

7
samples/BookStore/src/BookStore.Domain.Shared/Identity/IdentityUserType.cs

@ -0,0 +1,7 @@
namespace BookStore.Identity;
public enum IdentityUserType
{
Normal,
Basic
}

5
samples/BookStore/src/BookStore.Domain.Shared/Localization/BookStore/en.json

@ -3,6 +3,9 @@
"texts": {
"Menu:Home": "Home",
"Welcome": "Welcome",
"LongWelcomeMessage": "Welcome to the application. This is a startup project based on the ABP framework. For more information, visit abp.io."
"LongWelcomeMessage": "Welcome to the application. This is a startup project based on the ABP framework. For more information, visit abp.io.",
"IdentityUserType": "User Type",
"Enum:IdentityUserType.Normal": "Normal User",
"Enum:IdentityUserType.Basic": "Basic User"
}
}

17
samples/BookStore/src/BookStore.Domain.Shared/Localization/BookStore/zh-Hans.json

@ -1,8 +1,11 @@
{
"culture": "zh-Hans",
"texts": {
"Menu:Home": "首页",
"Welcome": "欢迎",
"LongWelcomeMessage": "欢迎来到该应用程序. 这是一个基于ABP框架的启动项目. 有关更多信息, 请访问 abp.io."
}
}
"culture": "zh-Hans",
"texts": {
"Menu:Home": "首页",
"Welcome": "欢迎",
"LongWelcomeMessage": "欢迎来到该应用程序. 这是一个基于ABP框架的启动项目. 有关更多信息, 请访问 abp.io.",
"IdentityUserType": "用户类型",
"Enum:IdentityUserType.Normal": "标准用户",
"Enum:IdentityUserType.Basic": "基础用户"
}
}

4
src/Lsw.Abp.AntDesignUI/AbpCrudPageBase.cs

@ -178,6 +178,8 @@ public abstract class AbpCrudPageBase<
[Inject] protected IStringLocalizer<AbpUiResource> UiLocalizer { get; set; }
[Inject] protected IAbpEnumLocalizer AbpEnumLocalizer { get; set; }
protected virtual int PageSize { get; } = LimitedResultRequestDto.DefaultMaxResultCount;
protected int CurrentPage = 1;
@ -618,7 +620,7 @@ public abstract class AbpCrudPageBase<
if (propertyInfo.Type.IsEnum)
{
column.ValueConverter = (val) =>
EnumHelper.GetLocalizedMemberName(propertyInfo.Type, val.As<ExtensibleObject>().ExtraProperties[propertyInfo.Name], StringLocalizerFactory);
AbpEnumLocalizer.GetString(propertyInfo.Type, val.As<ExtensibleObject>().ExtraProperties[propertyInfo.Name]);
}
yield return column;

28
src/Lsw.Abp.AntDesignUI/Components/ObjectExtending/EnumHelper.cs

@ -1,28 +0,0 @@
using System;
using Microsoft.Extensions.Localization;
using Volo.Abp.Localization;
namespace Lsw.Abp.AntDesignUI.Components.ObjectExtending;
public static class EnumHelper
{
public static string GetLocalizedMemberName(Type enumType, object value, IStringLocalizerFactory stringLocalizerFactory)
{
var memberName = enumType.GetEnumName(value);
var localizedMemberName = AbpInternalLocalizationHelper.LocalizeWithFallback(
new[]
{
stringLocalizerFactory.CreateDefaultOrNull()
},
new[]
{
$"Enum:{enumType.Name}.{memberName}",
$"{enumType.Name}.{memberName}",
memberName
},
memberName
);
return localizedMemberName;
}
}

4
src/Lsw.Abp.AntDesignUI/Components/ObjectExtending/ExtensionPropertyComponentBase.cs

@ -3,6 +3,7 @@ using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.Localization;
using Volo.Abp.AspNetCore.Components.Web;
using Volo.Abp.Data;
using Volo.Abp.Localization;
using Volo.Abp.ObjectExtending;
namespace Lsw.Abp.AntDesignUI.Components.ObjectExtending;
@ -13,6 +14,9 @@ public abstract class ExtensionPropertyComponentBase<TEntity, TResourceType> : O
[Inject]
public IStringLocalizerFactory StringLocalizerFactory { get; set; }
[Inject]
public IAbpEnumLocalizer EnumLocalizer { get; set; }
[Parameter]
public TEntity Entity { get; set; }

2
src/Lsw.Abp.AntDesignUI/Components/ObjectExtending/SelectExtensionProperty.razor.cs

@ -22,7 +22,7 @@ public partial class SelectExtensionProperty<TEntity, TResourceType>
selectItems.Add(new SelectItem<int>
{
Value = (int)enumValue,
Text = EnumHelper.GetLocalizedMemberName(PropertyInfo.Type, enumValue, StringLocalizerFactory)
Text = EnumLocalizer.GetString(PropertyInfo.Type, enumValue)
});
}

Loading…
Cancel
Save