LocalizationOptions Pennington.Infrastructure
Options for localization.
Properties
DefaultLocalestring- Default:
"en"Locale code used when no URL locale prefix is present. IsMultiLocalebool- True when more than one locale is configured.
LocalesSystem.Collections.Generic.IReadOnlyDictionary<string, Pennington.Localization.LocaleInfo>- Configured locales keyed by locale code.
Methods
AddLocale
#public void AddLocale(string code, LocaleInfo info);Registers a locale with the supplied metadata.
Parameters
codestringinfoLocaleInfo
AddLocale
#public void AddLocale(string code, string displayName);Registers a locale with just a display name.
Parameters
codestringdisplayNamestring
BuildLocaleUrl
#public string BuildLocaleUrl(string contentPath, string locale);Builds a full URL for a content path in a specific locale.
Parameters
contentPathstringlocalestring
Returns
stringGetAlternateLanguages
#public IReadOnlyList<AlternateLanguage> GetAlternateLanguages(string url);Gets alternate language versions for a page URL across all configured locales. Pure URL math — does not check if content exists (fallback handles that).
Parameters
urlstring
Returns
IReadOnlyList<AlternateLanguage>GetLocaleFromUrl
#public string GetLocaleFromUrl(string url);Extracts the locale code from a URL path. Returns the default locale when the first segment is not a known non-default locale.
Parameters
urlstring
Returns
stringStripLocalePrefix
#public string StripLocalePrefix(string url, string locale);Strips the locale prefix from a URL, returning the content-relative path. For the default locale (no prefix), returns the URL unchanged.
Parameters
urlstringlocalestring
Returns
stringPennington.Infrastructure.LocalizationOptions
namespace Pennington.Infrastructure;
/// Options for localization.
public class LocalizationOptions
{
/// Registers a locale with the supplied metadata.
public void AddLocale(string code, LocaleInfo info);
/// Registers a locale with just a display name.
public void AddLocale(string code, string displayName);
/// Builds a full URL for a content path in a specific locale.
public string BuildLocaleUrl(string contentPath, string locale);
/// Locale code used when no URL locale prefix is present.
public string DefaultLocale { get; set; } = "en";
/// Gets alternate language versions for a page URL across all configured locales. Pure URL math — does not check if content exists (fallback handles that).
public IReadOnlyList<AlternateLanguage> GetAlternateLanguages(string url);
/// Extracts the locale code from a URL path. Returns the default locale when the first segment is not a known non-default locale.
public string GetLocaleFromUrl(string url);
/// True when more than one locale is configured.
public bool IsMultiLocale => _locales.Count > 1;
/// Configured locales keyed by locale code.
public IReadOnlyDictionary<string, LocaleInfo> Locales => _locales;
/// Strips the locale prefix from a URL, returning the content-relative path. For the default locale (no prefix), returns the URL unchanged.
public string StripLocalePrefix(string url, string locale);
}