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

LocaleContext Pennington.Localization

Scoped per-request locale context, set by LocaleDetectionMiddleware. Provides the current locale and locale-aware URL building for Razor components. Analogous to Astro's Astro.currentLocale.

Properties

ContentPath string
The request URL with locale prefix stripped (e.g., "/schedule" regardless of locale).
Direction string
Text direction for this locale ("ltr" or "rtl").
HtmlLang string
The HTML lang attribute value for this locale.
Info LocaleInfo
Metadata for this locale.
IsDefaultLocale bool
True when the current locale is the default locale.
Locale string
The Pennington locale code for this request (e.g., "en", "fr", "gen-z").

Constructors

LocaleContext

#
public LocaleContext(LocalizationOptions localization)

Creates the context, initialized to the default locale until middleware populates the request's locale.

Parameters

localization LocalizationOptions

Methods

Url

#
public string Url(string path)

Builds a locale-aware URL from a content path. For the default locale, returns the path as-is. For other locales, prefixes with /{locale}/.

Parameters

path string

Returns

string

Pennington.Localization.LocaleContext

namespace Pennington.Localization;

/// Scoped per-request locale context, set by LocaleDetectionMiddleware. Provides the current locale and locale-aware URL building for Razor components. Analogous to Astro's Astro.currentLocale.
public class LocaleContext
{
    /// The request URL with locale prefix stripped (e.g., "/schedule" regardless of locale).
    
public string ContentPath { get; set; }
/// Text direction for this locale ("ltr" or "rtl").
public string Direction { get; }
/// The HTML lang attribute value for this locale.
public string HtmlLang { get; }
/// Metadata for this locale.
public LocaleInfo Info { get; set; }
/// True when the current locale is the default locale.
public bool IsDefaultLocale { get; set; }
/// The Pennington locale code for this request (e.g., "en", "fr", "gen-z").
public string Locale { get; set; }
/// Creates the context, initialized to the default locale until middleware populates the request's locale.
public LocaleContext(LocalizationOptions localization)
; /// Builds a locale-aware URL from a content path. For the default locale, returns the path as-is. For other locales, prefixes with /{locale}/.
public string Url(string path)
; }