Browse Source

Created AbpIdentityBlazorMessageLocalizerHelper instead of extension methods

pull/5883/head
Mladen Macanovic 6 years ago
parent
commit
c4cc529f39
  1. 17
      modules/identity/src/Volo.Abp.Identity.Blazor/AbpIdentityBlazorMessageLocalizerHelper.cs
  2. 2
      modules/identity/src/Volo.Abp.Identity.Blazor/AbpIdentityBlazorModule.cs
  3. 7
      modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/RoleManagement.razor
  4. 27
      modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/UserManagement.razor

17
modules/identity/src/Volo.Abp.Identity.Blazor/AbpIdentityBlazorMessageLocalizerExtensions.cs → modules/identity/src/Volo.Abp.Identity.Blazor/AbpIdentityBlazorMessageLocalizerHelper.cs

@ -1,18 +1,25 @@
using System.Collections.Generic;
using System.Linq;
using Blazorise;
using JetBrains.Annotations;
using Microsoft.Extensions.Localization;
namespace Volo.Abp.Identity.Blazor
{
public static class AbpIdentityBlazorMessageLocalizerExtensions
public class AbpIdentityBlazorMessageLocalizerHelper<T>
{
public static string Localize<T>(this IStringLocalizer<T> stringLocalizer, string message, IEnumerable<string> arguments)
private readonly IStringLocalizer<T> stringLocalizer;
public AbpIdentityBlazorMessageLocalizerHelper(IStringLocalizer<T> stringLocalizer)
{
this.stringLocalizer = stringLocalizer;
}
public string Localize(string message, [CanBeNull] IEnumerable<string> arguments)
{
try
{
return arguments?.Count() > 0
? stringLocalizer[message, LocalizeMessageArguments(stringLocalizer, arguments)?.ToArray()]
? stringLocalizer[message, LocalizeMessageArguments(arguments)?.ToArray()]
: stringLocalizer[message];
}
catch
@ -21,7 +28,7 @@ namespace Volo.Abp.Identity.Blazor
}
}
private static IEnumerable<string> LocalizeMessageArguments<T>(IStringLocalizer<T> stringLocalizer, IEnumerable<string> arguments)
private IEnumerable<string> LocalizeMessageArguments(IEnumerable<string> arguments)
{
foreach (var argument in arguments)
{

2
modules/identity/src/Volo.Abp.Identity.Blazor/AbpIdentityBlazorModule.cs

@ -32,6 +32,8 @@ namespace Volo.Abp.Identity.Blazor
{
options.AdditionalAssemblies.Add(typeof(AbpIdentityBlazorModule).Assembly);
});
context.Services.AddSingleton(typeof(AbpIdentityBlazorMessageLocalizerHelper<>));
}
}
}

7
modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/RoleManagement.razor

@ -1,5 +1,5 @@
@page "/identity/roles"
@attribute [Authorize(IdentityPermissions.Roles.Default)]
@attribute [Authorize( IdentityPermissions.Roles.Default )]
@using Volo.Abp.Identity
@using Microsoft.AspNetCore.Authorization
@using Microsoft.Extensions.Localization
@ -7,6 +7,7 @@
@using Volo.Abp.PermissionManagement.Blazor.Components
@inherits RoleManagementBase
@inject IStringLocalizer<IdentityResource> L
@inject AbpIdentityBlazorMessageLocalizerHelper<IdentityResource> LH
@* ************************* PAGE HEADER ************************* *@
<Row>
<Column ColumnSize="ColumnSize.Is6">
@ -84,7 +85,7 @@
</ModalHeader>
<ModalBody>
<Validations @ref="@CreateValidationsRef" Model="@NewEntity" ValidateOnLoad="false">
<Validation MessageLocalizer="@L.Localize">
<Validation MessageLocalizer="@LH.Localize">
<Field>
<FieldLabel>@L["DisplayName:RoleName"]</FieldLabel>
<TextEdit @bind-Text="@NewEntity.Name">
@ -120,7 +121,7 @@
<ModalBody>
<Validations @ref="@EditValidationsRef" Model="@EditingEntity" ValidateOnLoad="false">
<input type="hidden" name="ConcurrencyStamp" @bind-value="EditingEntity.ConcurrencyStamp" />
<Validation MessageLocalizer="@L.Localize">
<Validation MessageLocalizer="@LH.Localize">
<Field>
<FieldLabel>@L["DisplayName:RoleName"]</FieldLabel>
<TextEdit @bind-Text="EditingEntity.Name">

27
modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/UserManagement.razor

@ -1,11 +1,12 @@
@page "/identity/users"
@attribute [Authorize(IdentityPermissions.Users.Default)]
@attribute [Authorize( IdentityPermissions.Users.Default )]
@using Microsoft.AspNetCore.Authorization
@using Microsoft.Extensions.Localization
@using Volo.Abp.Identity.Localization
@using Volo.Abp.PermissionManagement.Blazor.Components
@inherits UserManagementBase
@inject IStringLocalizer<IdentityResource> L
@inject AbpIdentityBlazorMessageLocalizerHelper<IdentityResource> LH
@* ************************* PAGE HEADER ************************* *@
<Row>
<Column ColumnSize="ColumnSize.Is6">
@ -93,7 +94,7 @@
</Items>
<Content>
<TabPanel Name="UserInformations">
<Validation MessageLocalizer="@L.Localize">
<Validation MessageLocalizer="@LH.Localize">
<Field>
<FieldLabel>@L["DisplayName:UserName"]</FieldLabel>
<TextEdit @bind-Text="NewEntity.UserName">
@ -103,7 +104,7 @@
</TextEdit>
</Field>
</Validation>
<Validation MessageLocalizer="@L.Localize">
<Validation MessageLocalizer="@LH.Localize">
<Field>
<FieldLabel>@L["DisplayName:Name"]</FieldLabel>
<TextEdit @bind-Text="NewEntity.Name">
@ -113,7 +114,7 @@
</TextEdit>
</Field>
</Validation>
<Validation MessageLocalizer="@L.Localize">
<Validation MessageLocalizer="@LH.Localize">
<Field>
<FieldLabel>@L["DisplayName:Surname"]</FieldLabel>
<TextEdit @bind-Text="NewEntity.Surname">
@ -123,7 +124,7 @@
</TextEdit>
</Field>
</Validation>
<Validation MessageLocalizer="@L.Localize">
<Validation MessageLocalizer="@LH.Localize">
<Field>
<FieldLabel>@L["DisplayName:Password"]</FieldLabel>
<TextEdit Role="TextRole.Password" @bind-Text="NewEntity.Password">
@ -133,7 +134,7 @@
</TextEdit>
</Field>
</Validation>
<Validation MessageLocalizer="@L.Localize">
<Validation MessageLocalizer="@LH.Localize">
<Field>
<FieldLabel>@L["DisplayName:Email"]</FieldLabel>
<TextEdit @bind-Text="NewEntity.Email">
@ -143,7 +144,7 @@
</TextEdit>
</Field>
</Validation>
<Validation MessageLocalizer="@L.Localize">
<Validation MessageLocalizer="@LH.Localize">
<Field>
<FieldLabel>@L["DisplayName:PhoneNumber"]</FieldLabel>
<TextEdit @bind-Text="NewEntity.PhoneNumber">
@ -202,7 +203,7 @@
</Items>
<Content>
<TabPanel Name="UserInformations">
<Validation MessageLocalizer="@L.Localize">
<Validation MessageLocalizer="@LH.Localize">
<Field>
<FieldLabel>@L["DisplayName:UserName"]</FieldLabel>
<TextEdit @bind-Text="EditingEntity.UserName">
@ -212,7 +213,7 @@
</TextEdit>
</Field>
</Validation>
<Validation MessageLocalizer="@L.Localize">
<Validation MessageLocalizer="@LH.Localize">
<Field>
<FieldLabel>@L["DisplayName:Name"]</FieldLabel>
<TextEdit @bind-Text="EditingEntity.Name">
@ -222,7 +223,7 @@
</TextEdit>
</Field>
</Validation>
<Validation MessageLocalizer="@L.Localize">
<Validation MessageLocalizer="@LH.Localize">
<Field>
<FieldLabel>@L["DisplayName:Surname"]</FieldLabel>
<TextEdit @bind-Text="EditingEntity.Surname">
@ -232,7 +233,7 @@
</TextEdit>
</Field>
</Validation>
<Validation MessageLocalizer="@L.Localize">
<Validation MessageLocalizer="@LH.Localize">
<Field>
<FieldLabel>@L["DisplayName:Password"]</FieldLabel>
<TextEdit Role="TextRole.Password" @bind-Text="EditingEntity.Password">
@ -242,7 +243,7 @@
</TextEdit>
</Field>
</Validation>
<Validation MessageLocalizer="@L.Localize">
<Validation MessageLocalizer="@LH.Localize">
<Field>
<FieldLabel>@L["DisplayName:Email"]</FieldLabel>
<TextEdit @bind-Text="EditingEntity.Email">
@ -252,7 +253,7 @@
</TextEdit>
</Field>
</Validation>
<Validation MessageLocalizer="@L.Localize">
<Validation MessageLocalizer="@LH.Localize">
<Field>
<FieldLabel>@L["DisplayName:PhoneNumber"]</FieldLabel>
<TextEdit @bind-Text="EditingEntity.PhoneNumber">

Loading…
Cancel
Save