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
ContentPathstring- The request URL with locale prefix stripped (e.g., "/schedule" regardless of locale).
Directionstring- Text direction for this locale ("ltr" or "rtl").
HtmlLangstring- The HTML
langattribute value for this locale. InfoPennington.Localization.LocaleInfo- Metadata for this locale.
IsDefaultLocalebool- Default:
falseTrue when the current locale is the default locale. Localestring- 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
localizationLocalizationOptions
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
pathstring
Returns
stringPennington.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);
}