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
Orderint- 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 separateIResponseProcessors.
Constructors
FallbackLangHtmlRewriter
#public FallbackLangHtmlRewriter(LocalizationOptions localization)
Creates the rewriter.
Parameters
localizationLocalizationOptions
Fields
FallbackContentLocaleKeystring- 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
documentIDocumentcontextHttpContext
Returns
TaskShouldApply
#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
contextHttpContext
Returns
boolPennington.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)
;
}