Skip to content

Commit

Permalink
Merge pull request #2473 from abpframework/Localize-exception-message…
Browse files Browse the repository at this point in the history
…-on-LimitedResultRequestDto

Localize exception message on limited result request dto
  • Loading branch information
yekalkan authored Dec 26, 2019
2 parents ec67983 + a6b48ab commit a0adc32
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 3 deletions.
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>;

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."
}
}

0 comments on commit a0adc32

Please sign in to comment.