diff --git a/modules/identity/src/Volo.Abp.Identity.Blazor/AbpIdentityBlazorMessageLocalizerExtensions.cs b/modules/identity/src/Volo.Abp.Identity.Blazor/AbpIdentityBlazorMessageLocalizerExtensions.cs index 480b17ac14..bb5214ac63 100644 --- a/modules/identity/src/Volo.Abp.Identity.Blazor/AbpIdentityBlazorMessageLocalizerExtensions.cs +++ b/modules/identity/src/Volo.Abp.Identity.Blazor/AbpIdentityBlazorMessageLocalizerExtensions.cs @@ -1,15 +1,44 @@ using System.Collections.Generic; using System.Linq; using Blazorise; +using Microsoft.Extensions.Localization; namespace Volo.Abp.Identity.Blazor { public static class AbpIdentityBlazorMessageLocalizerExtensions { - public static IEnumerable Localize(this AbpIdentityMessageLocalizer abpIdentityMessageLocalizer, - ValidationMessageLocalizerEventArgs eventArgs) + public static IEnumerable Localize(this IStringLocalizer stringLocalizer, ValidationMessageLocalizerEventArgs eventArgs) { - return abpIdentityMessageLocalizer.Localize(eventArgs.Messages?.Select(m => (m.Message, m.MessageArguments)))?.ToArray(); + return LocalizeMessages(stringLocalizer, eventArgs.Messages?.Select(m => (m.Message, m.MessageArguments)))?.ToArray(); + } + + private static IEnumerable LocalizeMessages(IStringLocalizer stringLocalizer, IEnumerable<(string format, string[] arguments)> messages) + { + return messages?.Select(m => LocalizeMessage(stringLocalizer, m.format, m.arguments)); + } + + private static string LocalizeMessage(IStringLocalizer stringLocalizer, string format, params string[] arguments) + { + try + { + return arguments?.Length > 0 + ? string.Format(stringLocalizer[format], LocalizeMessageArguments(stringLocalizer, arguments)?.ToArray()) + : stringLocalizer[format]; + } + catch + { + return stringLocalizer[format]; + } + } + + private static IEnumerable LocalizeMessageArguments(IStringLocalizer stringLocalizer, IEnumerable arguments) + { + foreach (var argument in arguments) + { + yield return stringLocalizer[$"DisplayName:{argument}"] + ?? stringLocalizer[argument] + ?? argument; + } } } } diff --git a/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/RoleManagement.razor b/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/RoleManagement.razor index ef59e969fd..ac40aca83d 100644 --- a/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/RoleManagement.razor +++ b/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/RoleManagement.razor @@ -7,7 +7,6 @@ @using Volo.Abp.PermissionManagement.Blazor.Components @inherits RoleManagementBase @inject IStringLocalizer L -@inject AbpIdentityMessageLocalizer ML @* ************************* PAGE HEADER ************************* *@ @@ -85,7 +84,7 @@ - + @L["DisplayName:RoleName"] @@ -121,7 +120,7 @@ - + @L["DisplayName:RoleName"] diff --git a/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/UserManagement.razor b/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/UserManagement.razor index 0ed1fd3d5a..6f33181f8a 100644 --- a/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/UserManagement.razor +++ b/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/UserManagement.razor @@ -6,7 +6,6 @@ @using Volo.Abp.PermissionManagement.Blazor.Components @inherits UserManagementBase @inject IStringLocalizer L -@inject AbpIdentityMessageLocalizer ML @* ************************* PAGE HEADER ************************* *@ @@ -94,7 +93,7 @@ - + @L["DisplayName:UserName"] @@ -104,7 +103,7 @@ - + @L["DisplayName:Name"] @@ -114,7 +113,7 @@ - + @L["DisplayName:Surname"] @@ -124,7 +123,7 @@ - + @L["DisplayName:Password"] @@ -134,7 +133,7 @@ - + @L["DisplayName:Email"] @@ -144,7 +143,7 @@ - + @L["DisplayName:PhoneNumber"] @@ -203,7 +202,7 @@ - + @L["DisplayName:UserName"] @@ -213,7 +212,7 @@ - + @L["DisplayName:Name"] @@ -223,7 +222,7 @@ - + @L["DisplayName:Surname"] @@ -233,7 +232,7 @@ - + @L["DisplayName:Password"] @@ -243,7 +242,7 @@ - + @L["DisplayName:Email"] @@ -253,7 +252,7 @@ - + @L["DisplayName:PhoneNumber"] diff --git a/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/Identity/AbpIdentityDomainSharedModule.cs b/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/Identity/AbpIdentityDomainSharedModule.cs index 5a63d52b24..80d039b7d7 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/Identity/AbpIdentityDomainSharedModule.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/Identity/AbpIdentityDomainSharedModule.cs @@ -38,8 +38,6 @@ namespace Volo.Abp.Identity { options.MapCodeNamespace("Volo.Abp.Identity", typeof(IdentityResource)); }); - - context.Services.AddSingleton(typeof(AbpIdentityMessageLocalizer<>), typeof(AbpIdentityMessageLocalizer<>)); } } } diff --git a/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/Identity/AbpIdentityMessageLocalizer.cs b/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/Identity/AbpIdentityMessageLocalizer.cs deleted file mode 100644 index ff2c50ee83..0000000000 --- a/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/Identity/AbpIdentityMessageLocalizer.cs +++ /dev/null @@ -1,46 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using System.Linq; -using Microsoft.Extensions.Localization; - -namespace Volo.Abp.Identity -{ - public class AbpIdentityMessageLocalizer - { - private readonly IStringLocalizer stringLocalizer; - - public AbpIdentityMessageLocalizer(IStringLocalizer stringLocalizer) - { - this.stringLocalizer = stringLocalizer; - } - - public virtual string Localize(string format, params string[] arguments) - { - try - { - return arguments?.Length > 0 - ? string.Format(stringLocalizer[format], LocalizeArguments(arguments)?.ToArray()) - : stringLocalizer[format]; - } - catch - { - return stringLocalizer[format]; - } - } - - public virtual IEnumerable Localize(IEnumerable<(string format, string[] arguments)> messages) - { - return messages?.Select(m => Localize(m.format, m.arguments)); - } - - protected virtual IEnumerable LocalizeArguments(IEnumerable arguments) - { - foreach (var argument in arguments) - { - yield return stringLocalizer[$"DisplayName:{argument}"] - ?? stringLocalizer[argument] - ?? argument; - } - } - } -}