Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Localize exception message on limited result request dto #2473

Merged
merged 2 commits into from
Dec 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,14 @@
<RootNamespace />
</PropertyGroup>

<ItemGroup>
<EmbeddedResource Include="Volo\Abp\Application\Localization\Resources\AbpDdd\*.json" />
</ItemGroup>


<ItemGroup>
<ProjectReference Include="..\Volo.Abp.Auditing\Volo.Abp.Auditing.csproj" />
<ProjectReference Include="..\Volo.Abp.Localization\Volo.Abp.Localization.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@
using Volo.Abp.Auditing;
using Volo.Abp.Application.Localization.Resources.AbpDdd;
using Volo.Abp.Auditing;
using Volo.Abp.Localization;
using Volo.Abp.Modularity;
using Volo.Abp.VirtualFileSystem;

namespace Volo.Abp.Application
{
[DependsOn(
typeof(AbpAuditingModule)
typeof(AbpAuditingModule),
typeof(AbpLocalizationModule)
)]
public class AbpDddApplicationContractsModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
Configure<AbpVirtualFileSystemOptions>(options =>
{
options.FileSets.AddEmbedded<AbpDddApplicationContractsModule>();
});

Configure<AbpLocalizationOptions>(options =>
{
options.Resources
.Add<AbpDddResource>("en")
.AddVirtualJson("/Volo/Abp/Application/Localization/Resources/AbpDdd");
});
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using Microsoft.Extensions.Localization;
using Volo.Abp.Application.Localization.Resources.AbpDdd;

namespace Volo.Abp.Application.Dtos
{
Expand Down Expand Up @@ -30,9 +32,13 @@ public class LimitedResultRequestDto : ILimitedResultRequest, IValidatableObject

public virtual IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
var l = validationContext.GetService(typeof(IStringLocalizer<AbpDddResource>)) as IStringLocalizer<AbpDddResource>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this into the if (MaxResultCount > MaxMaxResultCount) to not call GetService unnecessarily if the request is already valid.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've done it: c010c56


if (MaxResultCount > MaxMaxResultCount)
{
yield return new ValidationResult($"{nameof(MaxResultCount)} can not be more than {MaxMaxResultCount}! Increase {typeof(LimitedResultRequestDto).FullName}.{nameof(MaxMaxResultCount)} on the server side to allow more results.", new []{nameof(MaxResultCount)});
yield return new ValidationResult(
errorMessage:l?["MaxResultCountExceededExceptionMessage", nameof(MaxResultCount), MaxMaxResultCount, typeof(LimitedResultRequestDto).FullName, nameof(MaxMaxResultCount)],
new []{nameof(MaxResultCount)});
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Volo.Abp.Localization;

namespace Volo.Abp.Application.Localization.Resources.AbpDdd
{
[LocalizationResourceName("AbpDdd")]
public class AbpDddResource
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"culture": "en",
"texts": {
"MaxResultCountExceededExceptionMessage": "{0} can not be more than {1}! Increase {2}.{3} on the server side to allow more results."
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"culture": "tr",
"texts": {
"MaxResultCountExceededExceptionMessage": "{0} en fazla {1} olabilir, daha büyük olamaz! Daha fazla sonuca izin vermek için {2}.{3}'ü sunucu tarafında artırın."
}
}