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

Skip to main content Skip to navigation

PenningtonStringLocalizer Pennington.Localization

An IStringLocalizer backed by TranslationOptions. Reads CurrentUICulture to determine the current locale, maps it back to a Pennington locale code, and looks up translations with fallback to the default locale, then to the key itself.

Properties

this[] Microsoft.Extensions.Localization.LocalizedString
Returns the translation for name, or the key itself when no translation is registered.
this[] Microsoft.Extensions.Localization.LocalizedString
Returns the translation for name formatted with arguments.

Constructors

.ctor

#
public PenningtonStringLocalizer(TranslationOptions translations, LocalizationOptions localization);

Creates the localizer.

Parameters

translations TranslationOptions
localization LocalizationOptions

Methods

GetAllStrings

#
public IEnumerable<LocalizedString> GetAllStrings(bool includeParentCultures);

Enumerates registered strings for the active locale, optionally including default-locale fallbacks.

Parameters

includeParentCultures bool

Returns

IEnumerable<LocalizedString>

Pennington.Localization.PenningtonStringLocalizer

namespace Pennington.Localization;

/// An IStringLocalizer backed by TranslationOptions. Reads CurrentUICulture to determine the current locale, maps it back to a Pennington locale code, and looks up translations with fallback to the default locale, then to the key itself.
public class PenningtonStringLocalizer
{
    /// Creates the localizer.
    
public PenningtonStringLocalizer(TranslationOptions translations, LocalizationOptions localization);
/// Enumerates registered strings for the active locale, optionally including default-locale fallbacks.
public IEnumerable<LocalizedString> GetAllStrings(bool includeParentCultures);
/// Returns the translation for name, or the key itself when no translation is registered.
public LocalizedString this[string name]
{
    get
    {
        var value = GetTranslation(name);
        return new LocalizedString(name, value ?? name, resourceNotFound: value is null);
    }
}
/// Returns the translation for name formatted with arguments.
public LocalizedString this[string name, params object[] arguments]
{
    get
    {
        var value = GetTranslation(name);
        var formatted = value is not null
            ? string.Format(CultureInfo.CurrentCulture, value, arguments)
            : string.Format(CultureInfo.CurrentCulture, name, arguments);
        return new LocalizedString(name, formatted, resourceNotFound: value is null);
    }
}
}