Table of Contents

Class TlumachStringLocalizerFactory

Namespace
Tlumach.Extensions.Localization
Assembly
Tlumach.Extensions.Localization.dll

Creates instances of TlumachStringLocalizer.

The localizers are created anew on every call (IStringLocalizer<T> is transient), but the translation managers that the factory creates are cached: those created from options by what the options describe (the Configuration instance, or the DefaultFile with its assembly and locale, together with the text processing mode), not by the options instance, and those created for a base name without options by the base name and the assembly (the one that the location names, or the calling one). So the localizers do not load translations again even when the settings provider returns new options objects. The options are still requested for every localizer, so a provider can switch a context to another manager at runtime.

public sealed class TlumachStringLocalizerFactory : IStringLocalizerFactory
Inheritance
TlumachStringLocalizerFactory
Implements
Inherited Members

Constructors

TlumachStringLocalizerFactory(ITlumachSettingsProvider)

Initializes a new instance of the TlumachStringLocalizerFactory class using the given configuration provider.

public TlumachStringLocalizerFactory(ITlumachSettingsProvider settingsProvider)

Parameters

settingsProvider ITlumachSettingsProvider

The options to use when creating TlumachStringLocalizer instances.

Methods

Create(string, string)

Creates an instance of TlumachStringLocalizer from the options for the context or, when they set none of TranslationManager, Configuration, and DefaultFile, from the default file named baseName, embedded into resources of the assembly that location names or, when location is empty or is not the name of a loadable assembly, of the assembly that is calling this method.

As for ResourceManagerStringLocalizerFactory, location is the name of the assembly that holds the resources, so the file is found also when framework code (such as HtmlLocalizerFactory of MVC) calls this method on behalf of the application. A location that is not an assembly name does not cause an error, because it may be meant only as a part of the options context.

A DefaultFile of the options is loaded from Assembly or, when that is not set, from the entry assembly; location does not change that.

The localizer created from the default file named baseName uses CurrentCulture for a culture and DotNet text processing mode for texts with placeholders. An application can change either of these settings later by calling WithCulture(CultureInfo) or WithTextProcessingMode(TextFormat) method respectively.

public IStringLocalizer Create(string baseName, string location)

Parameters

baseName string

The name of the default file.

location string

The name (simple or full) of the assembly whose resources contain the default file named baseName, or an empty string to use the calling assembly. When not empty, it is also a part of the options context, location.baseName.

Returns

IStringLocalizer

An instance of TlumachStringLocalizer.

Exceptions

TlumachException

Thrown if the default file provided in baseName was not found.

ArgumentNullException

Thrown if the baseName is null or empty.

Create(Type)

Creates an instance of TlumachStringLocalizer from the options or from the reference to the generated class.

A localizer created from the generated class processes texts with placeholders in the text processing mode of the configuration of the class (DotNet if the configuration sets none).

public IStringLocalizer Create(Type resourceSource)

Parameters

resourceSource Type

The type of the class created by Tlumach Generator.

Returns

IStringLocalizer

An instance of TlumachStringLocalizer.

Remarks

When the options do not carry a translation manager, this method falls back to reading the static TranslationManager property of resourceSource through reflection. In a trimmed or NativeAOT application that property may have been removed. Supply the manager through TranslationManager, Configuration, or DefaultFile instead — those paths are checked first and use no reflection at all.

Exceptions

TlumachException

Thrown if the TranslationManager instance cannot be obtained from the class provided in resourceSource.