This site provides a machine-readable index at /llms.txt.

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 Pennington.Localization.LocaleInfo
Metadata for this locale.
IsDefaultLocale bool
Default: false
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

.ctor

#
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
{
    /// Creates the context, initialized to the default locale until middleware populates the request's locale.
    
public LocaleContext(LocalizationOptions localization);
/// The request URL with locale prefix stripped (e.g., "/schedule" regardless of locale).
public string ContentPath { get; internal set; }
/// Text direction for this locale ("ltr" or "rtl").
public string Direction => Info.Direction;
/// The HTML lang attribute value for this locale.
public string HtmlLang => Info.HtmlLang ?? Locale;
/// Metadata for this locale.
public LocaleInfo Info { get; internal set; }
/// True when the current locale is the default locale.
public bool IsDefaultLocale { get; internal set; }
/// The Pennington locale code for this request (e.g., "en", "fr", "gen-z").
public string Locale { get; internal set; }
/// 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);
}