Table of Contents

Class TlumachLanguageManager

Namespace
Tlumach.FluentValidation
Assembly
Tlumach.FluentValidation.dll

The language manager of FluentValidation that takes the messages from Tlumach translations and falls back to the messages built into FluentValidation.

Assign an instance to ValidatorOptions.Global.LanguageManager, or call AddTlumachFluentValidation. The setting is process-wide, as FluentValidation offers no other way to supply a language manager.

public class TlumachLanguageManager : LanguageManager, ILanguageManager
Inheritance
LanguageManager
TlumachLanguageManager
Implements
ILanguageManager
Inherited Members
LanguageManager.Clear()
LanguageManager.Enabled
LanguageManager.Culture

Remarks

A message is chosen in this order:

  1. The Tlumach text for the culture: text found for the culture or its basic culture, or the text of the default file when that file is written in the language of the culture.
  2. The message built into FluentValidation for the culture.
  3. The text of the default file of Tlumach.
  4. The English message of FluentValidation.

The text is returned as it appears in the translation. The placeholder engine of Tlumach is not involved, so the placeholders of FluentValidation, such as {PropertyName}, reach the message formatter of FluentValidation intact.

The class holds no mutable state of its own apart from the inherited Culture and Enabled properties, and it can be used from many threads at once.

Constructors

TlumachLanguageManager(TranslationManager, TlumachLanguageManagerOptions?)

Initializes a new instance of the TlumachLanguageManager class.

public TlumachLanguageManager(TranslationManager translationManager, TlumachLanguageManagerOptions? options = null)

Parameters

translationManager TranslationManager

The translation manager that provides the messages, typically Strings.TranslationManager of a class created by Generator.

options TlumachLanguageManagerOptions

The options. The values are copied, so a later change of the options object has no effect. When null, the defaults apply.

Exceptions

ArgumentNullException

Thrown when translationManager is null.

ArgumentOutOfRangeException

Thrown when CultureSource is not a defined value.

Properties

CultureSource

Gets the culture source used when neither the caller nor Culture specifies a culture.

public MessageCultureSource CultureSource { get; }

Property Value

MessageCultureSource

FluentValidationGroup

Gets the group, in which the keys of FluentValidation are looked up. See FluentValidationGroup.

public string? FluentValidationGroup { get; }

Property Value

string

TranslationManager

Gets the translation manager that provides the messages.

public TranslationManager TranslationManager { get; }

Property Value

TranslationManager

Methods

GetString(string, CultureInfo?)

Returns the message template for the key, chosen as described in the remarks of the class.

public override string GetString(string key, CultureInfo? culture = null)

Parameters

key string

The key: the name of a validator, such as NotEmptyValidator, or an error code set with WithErrorCode.

culture CultureInfo

An optional culture. See ResolveCulture(CultureInfo?).

Returns

string

The template, or an empty string when neither Tlumach nor FluentValidation knows the key.

Exceptions

ArgumentNullException

Thrown when key is null.

ResolveCulture(CultureInfo?)

Returns the culture, for which a message is read: culture when it is given, otherwise Culture when it is set, otherwise the culture that CultureSource selects.

public CultureInfo ResolveCulture(CultureInfo? culture = null)

Parameters

culture CultureInfo

An optional explicit culture.

Returns

CultureInfo

The effective culture.