Table of Contents

Class CompositeLocalizer

Namespace
NuvTools.AspNetCore.Localization
Assembly
NuvTools.AspNetCore.dll

Provides a composite localization system that combines multiple IStringLocalizer instances with support for prefix-based routing and fallback resolution.

public class CompositeLocalizer
Inheritance
CompositeLocalizer
Inherited Members

Remarks

Keys can be prefixed with a localizer name followed by a colon (e.g., "Errors:ValidationFailed") to target a specific localizer. If the prefix is not found or the key is not found in the specified localizer, the system falls back to searching all registered localizers.

Constructors

CompositeLocalizer(Dictionary<string, IStringLocalizer>, ILogger<CompositeLocalizer>?)

Provides a composite localization system that combines multiple IStringLocalizer instances with support for prefix-based routing and fallback resolution.

public CompositeLocalizer(Dictionary<string, IStringLocalizer> namedLocalizers, ILogger<CompositeLocalizer>? logger = null)

Parameters

namedLocalizers Dictionary<string, IStringLocalizer>
logger ILogger<CompositeLocalizer>

Remarks

Keys can be prefixed with a localizer name followed by a colon (e.g., "Errors:ValidationFailed") to target a specific localizer. If the prefix is not found or the key is not found in the specified localizer, the system falls back to searching all registered localizers.

Properties

this[string]

Gets the localized string for the specified key.

public LocalizedString this[string key] { get; }

Parameters

key string

The localization key. Can be prefixed with a localizer name (e.g., "Errors:KeyName").

Property Value

LocalizedString

The localized string, or the key itself if not found.

this[string, object[]]

Gets the localized string for the specified key with formatting arguments.

public LocalizedString this[string key, params object[] arguments] { get; }

Parameters

key string

The localization key. Can be prefixed with a localizer name (e.g., "Errors:KeyName").

arguments object[]

The formatting arguments to apply to the localized string.

Property Value

LocalizedString

The formatted localized string, or the key itself if not found.

Methods

TryGetValue(string, out string, params object[])

Attempts to retrieve the localized value for the specified key.

public bool TryGetValue(string key, out string value, params object[] arguments)

Parameters

key string

The localization key. Can be prefixed with a localizer name (e.g., "Errors:KeyName").

value string

When this method returns, contains the localized value if found; otherwise, the key itself.

arguments object[]

The formatting arguments to apply to the localized string.

Returns

bool

true if the key was found and localized; otherwise, false.