Vertaalbestanden 4/6: Offerings-validatiemeldingen naar Texts/nl.json en en.json (offerings.validation.*)

GEDRAGSWIJZIGING (goedgekeurd): de validatiemeldingen waren Engels en zijn nu Nederlands bij Texts:DefaultLanguage=nl (alleen zichtbaar voor beheerders). De Engelse teksten zijn de oude meldingen, letterlijk. TextCatalog.Default omvat nu alle geladen SlpModularCms.*-assemblies (fallback buiten DI).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-15 20:44:38 +01:00
co-authored by Claude Sonnet 5.5
parent 3c3a29bacc
commit d12e44350e
13 changed files with 175 additions and 18 deletions
@@ -1,3 +1,4 @@
using SlpModularCms.Core.Texts;
using System.Security.Claims;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
@@ -59,7 +60,7 @@ public class PublicOfferingBannerController(IOfferingBannersService service) : C
{
position = string.IsNullOrEmpty(position) ? OfferingBannerPositions.Bottom : position;
if (!OfferingBannerPositions.IsValid(position))
return BadRequest(new { error = "Position must be 'top' or 'bottom'." });
return BadRequest(new { error = HttpTexts.From(HttpContext).Get(OfferingsTexts.Validation.Banner.Position) });
Response.Headers.CacheControl = "public, max-age=60";
var current = await service.GetActiveAsync(position);
@@ -19,5 +19,5 @@ public record CreateOfferingRequest(
) : IValidatableObject
{
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
=> OfferingSchedule.Validate(StartsAt, EndsAt);
=> OfferingSchedule.Validate(StartsAt, EndsAt, validationContext);
}
@@ -16,16 +16,16 @@ public class FeaturesValidationAttribute : ValidationAttribute
protected override ValidationResult? IsValid(object? value, ValidationContext validationContext)
{
if (value is not List<string> features)
return new ValidationResult("Features must be a list of strings.", [validationContext.MemberName!]);
return new ValidationResult(OfferingsTexts.From(validationContext).Get(OfferingsTexts.Validation.Features.NotAList), [validationContext.MemberName!]);
if (features.Count is < MinItems or > MaxItems)
return new ValidationResult(
$"Features must contain between {MinItems} and {MaxItems} items.",
OfferingsTexts.From(validationContext).Get(OfferingsTexts.Validation.Features.Count, args: [("min", MinItems), ("max", MaxItems)]),
[validationContext.MemberName!]);
if (features.Any(f => string.IsNullOrWhiteSpace(f) || f.Length > MaxItemLength))
return new ValidationResult(
$"Each feature must be non-empty and at most {MaxItemLength} characters.",
OfferingsTexts.From(validationContext).Get(OfferingsTexts.Validation.Features.Item, args: ("max", MaxItemLength)),
[validationContext.MemberName!]);
return ValidationResult.Success;
@@ -35,26 +35,27 @@ public record OfferingBannerRequest(
{
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
var texts = OfferingsTexts.From(validationContext);
if (!OfferingBannerPositions.IsValid(Position))
yield return new ValidationResult("Position must be 'top' or 'bottom'.", [nameof(Position)]);
yield return new ValidationResult(texts.Get(OfferingsTexts.Validation.Banner.Position), [nameof(Position)]);
else if (Position == OfferingBannerPositions.Top)
{
if (Text?.Trim().Length > OfferingBannerPositions.TopTextMaxLength)
yield return new ValidationResult($"A top banner text can be at most {OfferingBannerPositions.TopTextMaxLength} characters.", [nameof(Text)]);
yield return new ValidationResult(texts.Get(OfferingsTexts.Validation.Banner.TopTextTooLong, args: ("max", OfferingBannerPositions.TopTextMaxLength)), [nameof(Text)]);
}
else if (string.IsNullOrWhiteSpace(Title))
yield return new ValidationResult("A bottom banner needs a title.", [nameof(Title)]);
yield return new ValidationResult(texts.Get(OfferingsTexts.Validation.Banner.BottomNeedsTitle), [nameof(Title)]);
var hasLabel = !string.IsNullOrWhiteSpace(LinkLabel);
var hasUrl = !string.IsNullOrWhiteSpace(LinkUrl);
if (hasLabel != hasUrl)
yield return new ValidationResult("Link label and link URL must be given together.", [nameof(LinkLabel), nameof(LinkUrl)]);
yield return new ValidationResult(texts.Get(OfferingsTexts.Validation.Banner.LinkTogether), [nameof(LinkLabel), nameof(LinkUrl)]);
else if (hasUrl && !OfferingBannerLinks.IsAllowed(LinkUrl!.Trim()))
yield return new ValidationResult("Link URL must be an https:// address or a site path starting with '/'.", [nameof(LinkUrl)]);
yield return new ValidationResult(texts.Get(OfferingsTexts.Validation.Banner.LinkNotAllowed), [nameof(LinkUrl)]);
if (StartsAt is not null && EndsAt is not null && EndsAt <= StartsAt)
yield return new ValidationResult("EndsAt must be after StartsAt.", [nameof(EndsAt)]);
yield return new ValidationResult(texts.Get(OfferingsTexts.Validation.Schedule.EndAfterStart), [nameof(EndsAt)]);
}
}
@@ -6,10 +6,10 @@ namespace SlpModularCms.Modules.Offerings.Models;
/// <summary>The one rule for "is this offering shown right now", shared by the public list and the SEO injection.</summary>
public static class OfferingSchedule
{
public static IEnumerable<ValidationResult> Validate(DateTimeOffset? startsAt, DateTimeOffset? endsAt)
public static IEnumerable<ValidationResult> Validate(DateTimeOffset? startsAt, DateTimeOffset? endsAt, ValidationContext? context = null)
{
if (startsAt is not null && endsAt is not null && endsAt <= startsAt)
yield return new ValidationResult("EndsAt must be after StartsAt.", [nameof(OfferingBanner.EndsAt)]);
yield return new ValidationResult(OfferingsTexts.From(context).Get(OfferingsTexts.Validation.Schedule.EndAfterStart), [nameof(OfferingBanner.EndsAt)]);
}
/// <summary>Switched on, started (inclusive) and not yet ended (exclusive).</summary>
@@ -19,5 +19,5 @@ public record UpdateOfferingRequest(
) : IValidatableObject
{
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
=> OfferingSchedule.Validate(StartsAt, EndsAt);
=> OfferingSchedule.Validate(StartsAt, EndsAt, validationContext);
}
@@ -1,3 +1,4 @@
using SlpModularCms.Core.Texts;
using System.Diagnostics.CodeAnalysis;
using Microsoft.AspNetCore.Builder;
using Microsoft.EntityFrameworkCore;
@@ -28,6 +29,7 @@ public class OfferingsModule : IModule
options.ReplaceService<IHistoryRepository, NonLockingMySQLHistoryRepository>();
});
services.AddCmsTextsFrom(typeof(OfferingsModule).Assembly);
services.AddScoped<IOfferingRepository, OfferingRepository>();
services.AddScoped<IOfferingsService, OfferingsService>();
services.AddScoped<IIndexHtmlMarkerProvider, OfferingsIndexMarkers>();
@@ -0,0 +1,37 @@
using System.ComponentModel.DataAnnotations;
using SlpModularCms.Core.Texts;
namespace SlpModularCms.Modules.Offerings;
/// <summary>The keys of the Offerings module's texts (<c>Texts/nl.json</c>, <c>Texts/en.json</c>, key path <c>offerings.*</c>).</summary>
public static class OfferingsTexts
{
/// <summary>Messages of request validation, shown to the administrator.</summary>
public static class Validation
{
public static class Features
{
public static readonly TextKey NotAList = new("offerings.validation.features.notAList");
public static readonly TextKey Count = new("offerings.validation.features.count", "min", "max");
public static readonly TextKey Item = new("offerings.validation.features.item", "max");
}
public static class Banner
{
public static readonly TextKey Position = new("offerings.validation.banner.position");
public static readonly TextKey TopTextTooLong = new("offerings.validation.banner.topTextTooLong", "max");
public static readonly TextKey BottomNeedsTitle = new("offerings.validation.banner.bottomNeedsTitle");
public static readonly TextKey LinkTogether = new("offerings.validation.banner.linkTogether");
public static readonly TextKey LinkNotAllowed = new("offerings.validation.banner.linkNotAllowed");
}
public static class Schedule
{
public static readonly TextKey EndAfterStart = new("offerings.validation.schedule.endAfterStart");
}
}
/// <summary>The catalogue of the request being validated, or the shared default one outside a request (unit tests).</summary>
public static ITextCatalog From(ValidationContext? context)
=> context?.GetService(typeof(ITextCatalog)) as ITextCatalog ?? TextCatalog.Default;
}
@@ -16,4 +16,8 @@
<ProjectReference Include="..\SlpModularCms.Core\SlpModularCms.Core.csproj" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Texts\*.json" WithCulture="false" />
</ItemGroup>
</Project>
@@ -0,0 +1,21 @@
{
"offerings": {
"validation": {
"features": {
"notAList": "Features must be a list of strings.",
"count": "Features must contain between {min} and {max} items.",
"item": "Each feature must be non-empty and at most {max} characters."
},
"banner": {
"position": "Position must be 'top' or 'bottom'.",
"topTextTooLong": "A top banner text can be at most {max} characters.",
"bottomNeedsTitle": "A bottom banner needs a title.",
"linkTogether": "Link label and link URL must be given together.",
"linkNotAllowed": "Link URL must be an https:// address or a site path starting with '/'."
},
"schedule": {
"endAfterStart": "EndsAt must be after StartsAt."
}
}
}
}
@@ -0,0 +1,21 @@
{
"offerings": {
"validation": {
"features": {
"notAList": "Kenmerken moeten een lijst met teksten zijn.",
"count": "Kenmerken moeten tussen {min} en {max} items bevatten.",
"item": "Elk kenmerk mag niet leeg zijn en maximaal {max} tekens bevatten."
},
"banner": {
"position": "De locatie moet 'top' of 'bottom' zijn.",
"topTextTooLong": "De tekst van een bovenbalk mag maximaal {max} tekens bevatten.",
"bottomNeedsTitle": "Een banner onderaan heeft een titel nodig.",
"linkTogether": "Knoptekst en link moeten samen worden opgegeven.",
"linkNotAllowed": "De link moet een https://-adres zijn of een pad op de site dat met '/' begint."
},
"schedule": {
"endAfterStart": "Het einde moet na het begin liggen."
}
}
}
}