Table of Contents

Class TlumachStringLocalizer

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

The class that provides localization functionality.

public class TlumachStringLocalizer : IStringLocalizer
Inheritance
TlumachStringLocalizer
Implements
Inherited Members

Constructors

TlumachStringLocalizer(TranslationManager)

Initializes a new instance of the TlumachStringLocalizer class that uses the text processing mode of the default configuration of manager (DotNet if it has none), as TlumachStringLocalizer(TranslationManager, TextFormat?) does with null.

public TlumachStringLocalizer(TranslationManager manager)

Parameters

manager TranslationManager

The translation manager to take the translations from.

Exceptions

ArgumentNullException

manager is null.

TlumachStringLocalizer(TranslationManager, TextFormat?)

Initializes a new instance of the TlumachStringLocalizer class.

public TlumachStringLocalizer(TranslationManager manager, TextFormat? textProcessingMode)

Parameters

manager TranslationManager

The translation manager to take the translations from.

textProcessingMode TextFormat?

The text processing mode to use, or null to use the one of the default configuration of manager (DotNet if it has none).

Exceptions

ArgumentNullException

manager is null.

Properties

this[string]

Gets the localized string with the given name (key).

The value is the text of the translation entry as it stands, with the placeholders it contains left untouched, so that it can be used as a format string. To have the placeholders replaced with values, use the this[string, object[]] property.

When the key is not present in any translation, the value is the key itself and ResourceNotFound is true, which is the behaviour that the consumers of IStringLocalizer expect.

public LocalizedString this[string name] { get; }

Parameters

name string

The name (key) of the string to return.

Property Value

LocalizedString

The value of the string with an indicator of whether it was found.

this[string, object[]]

Gets the localized string with the given name (key).

If the string contains placeholders, they are replaced with the placeholder values provided in the arguments parameter.

When the key is not present in any translation, the value is the key formatted with arguments as a composite format string (string.Format) in the culture of the localizer, and ResourceNotFound is true, which is the behaviour that the consumers of IStringLocalizer expect: the localization of data annotations passes the default message of a validation attribute, such as "The {0} field is required.", as the key. A key that is not a valid composite format string for the arguments is returned as it stands instead of throwing a FormatException.

When WebEncodeValues is set, the value is HTML-encoded whether or not the key was found, because the arguments it contains may come from the user.

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

Parameters

name string

The name (key) of the string to return.

arguments object[]

The list of values to use to replace placeholders.

Property Value

LocalizedString

The value of the string with an indicator of whether it was found.

Methods

GetAllStrings(bool)

Returns all localized strings contained in the translation for the current culture and, optionally, for its parent cultures and the default translation.

Every key appears once. When a key is present in several translations of the chain, the value of the most specific culture wins, which is the behaviour that the consumers of IStringLocalizer expect.

public IEnumerable<LocalizedString> GetAllStrings(bool includeParentCultures)

Parameters

includeParentCultures bool

Indicates whether the strings from the parent cultures and from the default translation should be returned as well.

Returns

IEnumerable<LocalizedString>

The list of the localized strings.

WithCulture(CultureInfo)

Returns a localizer that retrieves the strings for the given culture instead of the culture of the thread.

public IStringLocalizer WithCulture(CultureInfo culture)

Parameters

culture CultureInfo

The culture to use.

Returns

IStringLocalizer

A new localizer. The one whose method was called is left untouched.

WithTextProcessingMode(TextFormat)

Returns a localizer that uses the given text processing mode when it processes text which contains placeholders.

public IStringLocalizer WithTextProcessingMode(TextFormat textProcessingMode)

Parameters

textProcessingMode TextFormat

The mode to use.

Returns

IStringLocalizer

A new localizer. The one whose method was called is left untouched.