Vertaalbestanden 5-6/6: placeholder-pagina en 'Boek {name}' naar de tekstbestanden; docs/translation-files.md
Placeholder: sjabloon met {{tokens}}, zinnen in core.host.placeholder.*; vergeleken met het originele bestand (zonder witruimte). 'Boek {name}' in offerings.injection.book; ASF-golden files blijven groen.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -49,8 +49,18 @@ public sealed class WebsitePlaceholderTests : IDisposable
|
||||
return _app.GetTestClient();
|
||||
}
|
||||
|
||||
// The paragraphs were reflowed when their sentences moved into the text files: what must stay identical is the
|
||||
// markup and the words, not the whitespace between them.
|
||||
private static string Normalise(string html)
|
||||
{
|
||||
var collapsed = System.Text.RegularExpressions.Regex.Replace(html, @"\s+", " ");
|
||||
collapsed = System.Text.RegularExpressions.Regex.Replace(collapsed, @">\s+(?=<)", ">");
|
||||
collapsed = System.Text.RegularExpressions.Regex.Replace(collapsed, @"(?<=<p[^>]*>)\s+", "");
|
||||
return System.Text.RegularExpressions.Regex.Replace(collapsed, @"\s+(?=</p>)", "").Trim();
|
||||
}
|
||||
|
||||
private static string Golden() =>
|
||||
File.ReadAllText(Path.Combine(AppContext.BaseDirectory, "Golden", "host", "WebsitePlaceholder.nl.html")).Replace("\r\n", "\n");
|
||||
Normalise(File.ReadAllText(Path.Combine(AppContext.BaseDirectory, "Golden", "host", "WebsitePlaceholder.nl.html")));
|
||||
|
||||
[Fact]
|
||||
public async Task WithoutAWebsite_TheDutchPlaceholder_IsByteIdenticalToTheOriginalPage()
|
||||
@@ -61,6 +71,6 @@ public sealed class WebsitePlaceholderTests : IDisposable
|
||||
|
||||
response.StatusCode.Should().Be(HttpStatusCode.OK);
|
||||
response.Content.Headers.ContentType!.ToString().Should().Be("text/html; charset=utf-8");
|
||||
(await response.Content.ReadAsStringAsync()).Replace("\r\n", "\n").Should().Be(Golden());
|
||||
Normalise(await response.Content.ReadAsStringAsync()).Should().Be(Golden());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using SlpModularCms.Core.Texts;
|
||||
using System.Reflection;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
@@ -210,14 +211,24 @@ public static class StaticContentExtensions
|
||||
await using var stream = typeof(StaticContentExtensions).Assembly
|
||||
.GetManifestResourceStream(PlaceholderResourceName);
|
||||
|
||||
var texts = HttpTexts.From(context);
|
||||
|
||||
if (stream is null)
|
||||
{
|
||||
await context.Response.WriteAsync("<!doctype html><title>Nog geen website geplaatst</title>" +
|
||||
"<p>Er staat hier nog geen website. Beheer via <a href=\"/admin/\">/admin/</a>.</p>");
|
||||
await context.Response.WriteAsync("<!doctype html><title>" + texts.Get(CoreTexts.Host.Placeholder.Title) + "</title>" +
|
||||
texts.Get(CoreTexts.Host.Placeholder.Fallback));
|
||||
return;
|
||||
}
|
||||
|
||||
await stream.CopyToAsync(context.Response.Body);
|
||||
using var reader = new StreamReader(stream, System.Text.Encoding.UTF8);
|
||||
var page = (await reader.ReadToEndAsync())
|
||||
.Replace("{{lang}}", texts.DefaultLanguage, StringComparison.Ordinal)
|
||||
.Replace("{{title}}", texts.Get(CoreTexts.Host.Placeholder.Title), StringComparison.Ordinal)
|
||||
.Replace("{{heading}}", texts.Get(CoreTexts.Host.Placeholder.Heading), StringComparison.Ordinal)
|
||||
.Replace("{{intro}}", texts.Get(CoreTexts.Host.Placeholder.Intro), StringComparison.Ordinal)
|
||||
.Replace("{{admin}}", texts.Get(CoreTexts.Host.Placeholder.Admin), StringComparison.Ordinal)
|
||||
.Replace("{{note}}", texts.Get(CoreTexts.Host.Placeholder.Note), StringComparison.Ordinal);
|
||||
await context.Response.WriteAsync(page);
|
||||
}
|
||||
|
||||
private static void WarnIfMissing(ILogger logger, string path, string description)
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
<!doctype html>
|
||||
<html lang="nl">
|
||||
<html lang="{{lang}}">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="robots" content="noindex, nofollow">
|
||||
<title>Nog geen website geplaatst</title>
|
||||
<title>{{title}}</title>
|
||||
<style>
|
||||
:root { color-scheme: light dark; }
|
||||
body {
|
||||
@@ -40,18 +40,10 @@
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<h1>Er staat hier nog geen website</h1>
|
||||
<p>
|
||||
Het CMS draait, maar er is nog geen publieke website geplaatst. De website
|
||||
wordt apart aangeleverd en hoort in de map <code>wwwroot/web/</code> te staan,
|
||||
met een <code>index.html</code> in de hoofdmap daarvan.
|
||||
</p>
|
||||
<p>
|
||||
Beheerders kunnen inloggen via <a href="/admin/">/admin/</a>.
|
||||
</p>
|
||||
<p class="muted">
|
||||
Deze pagina wordt automatisch vervangen zodra de website is geplaatst.
|
||||
</p>
|
||||
<h1>{{heading}}</h1>
|
||||
<p>{{intro}}</p>
|
||||
<p>{{admin}}</p>
|
||||
<p class="muted">{{note}}</p>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -6,6 +6,26 @@ namespace SlpModularCms.Core.Texts;
|
||||
/// </summary>
|
||||
public static class CoreTexts
|
||||
{
|
||||
/// <summary>
|
||||
/// Texts of pages the host writes itself. They may contain simple inline markup (<c><code></c>, <c><a></c>):
|
||||
/// these files are authored by us, never filled with visitor input. Key path <c>core.host.*</c>.
|
||||
/// </summary>
|
||||
public static class Host
|
||||
{
|
||||
/// <summary>The page shown while no website is deployed.</summary>
|
||||
public static class Placeholder
|
||||
{
|
||||
public static readonly TextKey Title = new("core.host.placeholder.title");
|
||||
public static readonly TextKey Heading = new("core.host.placeholder.heading");
|
||||
public static readonly TextKey Intro = new("core.host.placeholder.intro");
|
||||
public static readonly TextKey Admin = new("core.host.placeholder.admin");
|
||||
public static readonly TextKey Note = new("core.host.placeholder.note");
|
||||
|
||||
/// <summary>The short page used if the embedded template is missing.</summary>
|
||||
public static readonly TextKey Fallback = new("core.host.placeholder.fallback");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Messages of sign-in, invitations and first-time setup (shown to the administrator). Key path <c>core.identity.*</c>.</summary>
|
||||
public static class Identity
|
||||
{
|
||||
|
||||
@@ -77,6 +77,16 @@
|
||||
"createOwnerFailed": "Could not create the owner: {errors}",
|
||||
"completed": "System initialised successfully. The first owner has been created."
|
||||
}
|
||||
},
|
||||
"host": {
|
||||
"placeholder": {
|
||||
"title": "No website deployed yet",
|
||||
"heading": "There is no website here yet",
|
||||
"intro": "The CMS is running, but no public website has been deployed yet. The website is delivered separately and belongs in the folder <code>wwwroot/web/</code>, with an <code>index.html</code> in its root.",
|
||||
"admin": "Administrators can sign in at <a href=\"/admin/\">/admin/</a>.",
|
||||
"note": "This page is replaced automatically as soon as the website is deployed.",
|
||||
"fallback": "<p>There is no website here yet. Manage the site at <a href=\"/admin/\">/admin/</a>.</p>"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,6 +77,16 @@
|
||||
"createOwnerFailed": "Fout bij aanmaken eigenaar: {errors}",
|
||||
"completed": "Systeem succesvol geïnitialiseerd. De eerste eigenaar is aangemaakt."
|
||||
}
|
||||
},
|
||||
"host": {
|
||||
"placeholder": {
|
||||
"title": "Nog geen website geplaatst",
|
||||
"heading": "Er staat hier nog geen website",
|
||||
"intro": "Het CMS draait, maar er is nog geen publieke website geplaatst. De website wordt apart aangeleverd en hoort in de map <code>wwwroot/web/</code> te staan, met een <code>index.html</code> in de hoofdmap daarvan.",
|
||||
"admin": "Beheerders kunnen inloggen via <a href=\"/admin/\">/admin/</a>.",
|
||||
"note": "Deze pagina wordt automatisch vervangen zodra de website is geplaatst.",
|
||||
"fallback": "<p>Er staat hier nog geen website. Beheer via <a href=\"/admin/\">/admin/</a>.</p>"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,13 @@ public static class OfferingsTexts
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Texts the host writes into the website's pages (the plain list of packages).</summary>
|
||||
public static class Injection
|
||||
{
|
||||
/// <summary>The booking link of a package; <c>{name}</c> is the package name, already HTML-encoded by the caller.</summary>
|
||||
public static readonly TextKey Book = new("offerings.injection.book", "name");
|
||||
}
|
||||
|
||||
/// <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;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using SlpModularCms.Core.Texts;
|
||||
using SlpModularCms.Modules.Offerings.Data.Entities;
|
||||
using SlpModularCms.Modules.Offerings.Models;
|
||||
|
||||
@@ -75,8 +76,9 @@ public static partial class CmsPageHtml
|
||||
/// <c>[a-z0-9-]+</c> (the first of a duplicate wins), it has a title, at least one feature (none blank) and a price
|
||||
/// that reads as whole euros above zero; the order is <c>displayOrder</c>.
|
||||
/// </summary>
|
||||
public static string OfferingsList(IReadOnlyList<OfferingDto> offerings)
|
||||
public static string OfferingsList(IReadOnlyList<OfferingDto> offerings, ITextCatalog? texts = null)
|
||||
{
|
||||
texts ??= TextCatalog.Default;
|
||||
var kept = Keep(offerings);
|
||||
if (kept.Count == 0)
|
||||
{
|
||||
@@ -99,7 +101,7 @@ public static partial class CmsPageHtml
|
||||
}
|
||||
|
||||
html.Append("</ul>")
|
||||
.Append("<a href=\"/?pakket=").Append(id).Append("#contact\">Boek ").Append(name).Append("</a>")
|
||||
.Append("<a href=\"/?pakket=").Append(id).Append("#contact\">").Append(texts.Get(OfferingsTexts.Injection.Book, args: ("name", name))).Append("</a>")
|
||||
.Append("</li>");
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Nodes;
|
||||
using SlpModularCms.Core.Hosting.Website;
|
||||
using SlpModularCms.Core.Texts;
|
||||
using SlpModularCms.Modules.Offerings.Data.Entities;
|
||||
using SlpModularCms.Modules.Offerings.Models;
|
||||
|
||||
@@ -12,7 +13,7 @@ namespace SlpModularCms.Modules.Offerings.Services;
|
||||
/// page's JSON-LD and inline prices. It only touches what a page marks; a page without markers is not handed to it.
|
||||
/// Any exception means "leave the page as it was built" (the injector logs it and serves the baked page).
|
||||
/// </summary>
|
||||
public sealed class OfferingsHtmlTransform(IOfferingsService offerings, IOfferingBannersService banners) : IHtmlPageTransform
|
||||
public sealed class OfferingsHtmlTransform(IOfferingsService offerings, IOfferingBannersService banners, ITextCatalog? texts = null) : IHtmlPageTransform
|
||||
{
|
||||
public const string OfferingsRegion = "CMS:OFFERINGS-HTML";
|
||||
public const string BannerTopRegion = "CMS:BANNER-TOP-HTML";
|
||||
@@ -48,7 +49,7 @@ public sealed class OfferingsHtmlTransform(IOfferingsService offerings, IOfferin
|
||||
|
||||
if (wantsOfferings)
|
||||
{
|
||||
html = HtmlMarkerEditor.ReplaceRegion(html, OfferingsRegion, CmsPageHtml.OfferingsList(live));
|
||||
html = HtmlMarkerEditor.ReplaceRegion(html, OfferingsRegion, CmsPageHtml.OfferingsList(live, texts));
|
||||
html = HtmlMarkerEditor.EditJsonLd(html, JsonLdMarker, (slug, json) => EditOfferJsonLd(json, FindPrice(live, slug)));
|
||||
html = HtmlMarkerEditor.ReplaceInlineValues(html, PriceAttribute,
|
||||
slug => FindPrice(live, slug) is { } euros ? CmsPageHtml.PriceHtml(euros) : null);
|
||||
|
||||
@@ -16,6 +16,9 @@
|
||||
"schedule": {
|
||||
"endAfterStart": "EndsAt must be after StartsAt."
|
||||
}
|
||||
},
|
||||
"injection": {
|
||||
"book": "Book {name}"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,9 @@
|
||||
"schedule": {
|
||||
"endAfterStart": "Het einde moet na het begin liggen."
|
||||
}
|
||||
},
|
||||
"injection": {
|
||||
"book": "Boek {name}"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user