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
-
LanguageManagerTlumachLanguageManager
- Implements
-
ILanguageManager
- Inherited Members
-
LanguageManager.Clear()LanguageManager.EnabledLanguageManager.Culture
Remarks
A message is chosen in this order:
- 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.
- The message built into FluentValidation for the culture.
- The text of the default file of Tlumach.
- 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
translationManagerTranslationManagerThe translation manager that provides the messages, typically
Strings.TranslationManagerof a class created by Generator.optionsTlumachLanguageManagerOptionsThe 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
translationManageris 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
FluentValidationGroup
Gets the group, in which the keys of FluentValidation are looked up. See FluentValidationGroup.
public string? FluentValidationGroup { get; }
Property Value
TranslationManager
Gets the translation manager that provides the messages.
public TranslationManager TranslationManager { get; }
Property Value
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
keystringThe key: the name of a validator, such as
NotEmptyValidator, or an error code set withWithErrorCode.cultureCultureInfoAn 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
keyis 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
cultureCultureInfoAn optional explicit culture.
Returns
- CultureInfo
The effective culture.