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. InfoLocaleInfo- Metadata for this locale.
IsDefaultLocalebool- True when the current locale is the default locale.
Localestring- 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
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
{
/// 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)
;
}