From f703db96e50bf149e04ef17cde67efbd760dbcde Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Thu, 26 Dec 2019 11:53:40 +0300 Subject: [PATCH 1/2] Localize exception message on LimitedResultRequestDto resolves https://github.com/abpframework/abp/issues/2468 --- .../Volo.Abp.Ddd.Application.Contracts.csproj | 7 +++++++ .../Volo/Abp/Application/Dtos/LimitedResultRequestDto.cs | 8 +++++++- .../Application/Localization/AbpValidationResource.cs | 9 +++++++++ .../Volo/Abp/Application/Localization/en.json | 6 ++++++ .../Volo/Abp/Application/Localization/tr.json | 6 ++++++ 5 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Localization/AbpValidationResource.cs create mode 100644 framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Localization/en.json create mode 100644 framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Localization/tr.json diff --git a/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo.Abp.Ddd.Application.Contracts.csproj b/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo.Abp.Ddd.Application.Contracts.csproj index 0b6eaee362e..3aae9522d55 100644 --- a/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo.Abp.Ddd.Application.Contracts.csproj +++ b/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo.Abp.Ddd.Application.Contracts.csproj @@ -13,8 +13,15 @@ + + + + + + + \ No newline at end of file diff --git a/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Dtos/LimitedResultRequestDto.cs b/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Dtos/LimitedResultRequestDto.cs index 2273f384b74..a5f058437e4 100644 --- a/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Dtos/LimitedResultRequestDto.cs +++ b/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Dtos/LimitedResultRequestDto.cs @@ -1,6 +1,8 @@ using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; +using Microsoft.Extensions.Localization; +using Volo.Abp.Application.Localization; namespace Volo.Abp.Application.Dtos { @@ -30,9 +32,13 @@ public class LimitedResultRequestDto : ILimitedResultRequest, IValidatableObject public virtual IEnumerable Validate(ValidationContext validationContext) { + var l = validationContext.GetService(typeof(IStringLocalizer)) as IStringLocalizer; + 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)}); } } } diff --git a/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Localization/AbpValidationResource.cs b/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Localization/AbpValidationResource.cs new file mode 100644 index 00000000000..412a68287f8 --- /dev/null +++ b/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Localization/AbpValidationResource.cs @@ -0,0 +1,9 @@ +using Volo.Abp.Localization; + +namespace Volo.Abp.Application.Localization +{ + [LocalizationResourceName("AbpValidation")] + public class AbpValidationResource + { + } +} diff --git a/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Localization/en.json b/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Localization/en.json new file mode 100644 index 00000000000..2c514e6c180 --- /dev/null +++ b/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Localization/en.json @@ -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." + } +} diff --git a/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Localization/tr.json b/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Localization/tr.json new file mode 100644 index 00000000000..428f3484272 --- /dev/null +++ b/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Localization/tr.json @@ -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." + } +} \ No newline at end of file From a6b48ab4fe3afe56acfe59c2711278b94b4f77ba Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Thu, 26 Dec 2019 14:29:58 +0300 Subject: [PATCH 2/2] Localize exception message on LimitedResultRequestDto cont. --- .../Volo.Abp.Ddd.Application.Contracts.csproj | 3 +-- .../AbpDddApplicationContractsModule.cs | 22 +++++++++++++++++-- .../Dtos/LimitedResultRequestDto.cs | 4 ++-- .../Localization/AbpValidationResource.cs | 9 -------- .../Resources/AbpDdd/AbpDddResource.cs | 9 ++++++++ .../{ => Resources/AbpDdd}/en.json | 0 .../{ => Resources/AbpDdd}/tr.json | 0 7 files changed, 32 insertions(+), 15 deletions(-) delete mode 100644 framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Localization/AbpValidationResource.cs create mode 100644 framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Localization/Resources/AbpDdd/AbpDddResource.cs rename framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Localization/{ => Resources/AbpDdd}/en.json (100%) rename framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Localization/{ => Resources/AbpDdd}/tr.json (100%) diff --git a/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo.Abp.Ddd.Application.Contracts.csproj b/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo.Abp.Ddd.Application.Contracts.csproj index 3aae9522d55..6f1674f8ce2 100644 --- a/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo.Abp.Ddd.Application.Contracts.csproj +++ b/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo.Abp.Ddd.Application.Contracts.csproj @@ -14,8 +14,7 @@ - - + diff --git a/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/AbpDddApplicationContractsModule.cs b/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/AbpDddApplicationContractsModule.cs index e1070722216..3166152e892 100644 --- a/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/AbpDddApplicationContractsModule.cs +++ b/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/AbpDddApplicationContractsModule.cs @@ -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(options => + { + options.FileSets.AddEmbedded(); + }); + + Configure(options => + { + options.Resources + .Add("en") + .AddVirtualJson("/Volo/Abp/Application/Localization/Resources/AbpDdd"); + }); + } } } diff --git a/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Dtos/LimitedResultRequestDto.cs b/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Dtos/LimitedResultRequestDto.cs index a5f058437e4..9e4375051d3 100644 --- a/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Dtos/LimitedResultRequestDto.cs +++ b/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Dtos/LimitedResultRequestDto.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using Microsoft.Extensions.Localization; -using Volo.Abp.Application.Localization; +using Volo.Abp.Application.Localization.Resources.AbpDdd; namespace Volo.Abp.Application.Dtos { @@ -32,7 +32,7 @@ public class LimitedResultRequestDto : ILimitedResultRequest, IValidatableObject public virtual IEnumerable Validate(ValidationContext validationContext) { - var l = validationContext.GetService(typeof(IStringLocalizer)) as IStringLocalizer; + var l = validationContext.GetService(typeof(IStringLocalizer)) as IStringLocalizer; if (MaxResultCount > MaxMaxResultCount) { diff --git a/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Localization/AbpValidationResource.cs b/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Localization/AbpValidationResource.cs deleted file mode 100644 index 412a68287f8..00000000000 --- a/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Localization/AbpValidationResource.cs +++ /dev/null @@ -1,9 +0,0 @@ -using Volo.Abp.Localization; - -namespace Volo.Abp.Application.Localization -{ - [LocalizationResourceName("AbpValidation")] - public class AbpValidationResource - { - } -} diff --git a/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Localization/Resources/AbpDdd/AbpDddResource.cs b/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Localization/Resources/AbpDdd/AbpDddResource.cs new file mode 100644 index 00000000000..666a962a224 --- /dev/null +++ b/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Localization/Resources/AbpDdd/AbpDddResource.cs @@ -0,0 +1,9 @@ +using Volo.Abp.Localization; + +namespace Volo.Abp.Application.Localization.Resources.AbpDdd +{ + [LocalizationResourceName("AbpDdd")] + public class AbpDddResource + { + } +} diff --git a/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Localization/en.json b/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Localization/Resources/AbpDdd/en.json similarity index 100% rename from framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Localization/en.json rename to framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Localization/Resources/AbpDdd/en.json diff --git a/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Localization/tr.json b/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Localization/Resources/AbpDdd/tr.json similarity index 100% rename from framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Localization/tr.json rename to framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Localization/Resources/AbpDdd/tr.json