This documentation is also published as Markdown for efficient machine reading: the whole site is indexed at /llms.txt, and every page has a clean Markdown copy under /_llms/. These are generated from the same source and cost far fewer tokens to read than this rendered HTML.

Skip to main content Skip to navigation

FallbackLangHtmlRewriter Pennington.Localization

When a non-default-locale request was served with content from a different locale (fallback), rewrites <html lang="..." dir="..."> to match the actual content locale so screen readers and lang-aware tooling don't misidentify the body's language.

Signal carrier: pages that resolve a fallback set HttpContext.Items["Pennington.FallbackContentLocale"] to the locale code whose content was actually rendered. Absence of that key means no rewrite.

Properties

Order int
Sort order within the HTML rewriting pipeline. Rewriters run in ascending Order. Xref resolution at 10, locale prefixing at 20, base-URL prefixing at 30 — the outside-in order that was previously expressed across separate IResponseProcessors.

Constructors

FallbackLangHtmlRewriter

#
public FallbackLangHtmlRewriter(LocalizationOptions localization)

Creates the rewriter.

Parameters

localization LocalizationOptions

Fields

FallbackContentLocaleKey string
Default: "Pennington.FallbackContentLocale"
Key written by content-resolving pages when a fallback was used.

Methods

ApplyAsync

#
public Task ApplyAsync(IDocument document, HttpContext context)

Mutate the shared parsed document. The orchestrator serializes it once after every rewriter has run.

Parameters

document IDocument
context HttpContext

Returns

Task

ShouldApply

#
public bool ShouldApply(HttpContext context)

Cheap gate checked before parsing. Return false to skip both PreParseAsync and ApplyAsync for this response. If every rewriter returns false, the orchestrator skips parsing entirely.

Parameters

context HttpContext

Returns

bool

Pennington.Localization.FallbackLangHtmlRewriter

namespace Pennington.Localization;

/// When a non-default-locale request was served with content from a different locale (fallback), rewrites <html lang="..." dir="..."> to match the actual content locale so screen readers and lang-aware tooling don't misidentify the body's language. Signal carrier: pages that resolve a fallback set HttpContext.Items["Pennington.FallbackContentLocale"] to the locale code whose content was actually rendered. Absence of that key means no rewrite.
public class FallbackLangHtmlRewriter
{
    /// Mutate the shared parsed document. The orchestrator serializes it once after every rewriter has run.
    
public Task ApplyAsync(IDocument document, HttpContext context)
; /// Key written by content-resolving pages when a fallback was used.
public static const string FallbackContentLocaleKey
; /// Creates the rewriter.
public FallbackLangHtmlRewriter(LocalizationOptions localization)
; /// Sort order within the HTML rewriting pipeline. Rewriters run in ascending Order. Xref resolution at 10, locale prefixing at 20, base-URL prefixing at 30 — the outside-in order that was previously expressed across separate IResponseProcessors.
public int Order { get; }
/// Cheap gate checked before parsing. Return false to skip both PreParseAsync and ApplyAsync for this response. If every rewriter returns false, the orchestrator skips parsing entirely.
public bool ShouldApply(HttpContext context)
; }