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

Skip to main content Skip to navigation

LocalizationOptions Pennington.Infrastructure

Options for localization.

Properties

DefaultLocale string
Default: "en"
Locale code used when no URL locale prefix is present.
IsMultiLocale bool
True when more than one locale is configured.
Locales System.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

code string
info LocaleInfo

AddLocale

#
public void AddLocale(string code, string displayName);

Registers a locale with just a display name.

Parameters

code string
displayName string

BuildLocaleUrl

#
public string BuildLocaleUrl(string contentPath, string locale);

Builds a full URL for a content path in a specific locale.

Parameters

contentPath string
locale string

Returns

string

GetAlternateLanguages

#
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

url string

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

url string

Returns

string

StripLocalePrefix

#
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

url string
locale string

Returns

string

Pennington.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);
}