LocalizedString.FluentValidation 1.0.1

.NET Standard 2.0
Install-Package LocalizedString.FluentValidation -Version 1.0.1
dotnet add package LocalizedString.FluentValidation --version 1.0.1
<PackageReference Include="LocalizedString.FluentValidation" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add LocalizedString.FluentValidation --version 1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: LocalizedString.FluentValidation, 1.0.1"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install LocalizedString.FluentValidation as a Cake Addin
#addin nuget:?package=LocalizedString.FluentValidation&version=1.0.1

// Install LocalizedString.FluentValidation as a Cake Tool
#tool nuget:?package=LocalizedString.FluentValidation&version=1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

A helper library for FluentValidation that allows for easy declaration of error messages in various languages without the use of resource files. When ValidationResult is produced, the value of Thread.CurrentThread.CurrentCulture will be used to resolve the translations for the ErrorMessage fields.

Useful for short strings. If strings are getting longer -- consider switching to time-tested technique of using resource files.

The library uses LocalizedString, get more info here

Example:

class Student
{
    public string Name { get; set; }
    public double GPA { get; set; }
}

class StudentValidator : AbstractValidator<Student>
{
    public StudentValidator()
    {
        RuleFor(x => x.Name).MinimumLength(3).WithMessage(
            "Name must be at least 3 characters long".Localize()
            .InFrench("Le name must be at least 3 characters long")
            .InCanadianFrench("Le name must be at least 3 characters long, éh")
            .In("de-DE", "Das name must be at least 3 characters long"));

        RuleFor(x => x.GPA).Must(x => x >= 0 && x <= 4.0).WithMessage(
            "Must be from 0 to 4".Localize()
            .InFrench("Must be from 0 to 4, comprendre?")
            .InCanadianFrench("Must be from 0 to 4, s'il vous plaît")
            .In("de-DE", "Must be from 0 to 4, verstehen?"));
    }
}

var student = new Student()
{
    Name = "TJ",
    GPA = 4.1
};

var validator = new StudentValidator();

Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo(string.Empty); // invariant

var validationResult = validator.Validate(student);

Console.WriteLine(validationResult.Errors[0].ErrorMessage); // Name must be at least 3 characters long

Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("de-DE");

validationResult = validator.Validate(student);

Console.WriteLine(validationResult.Errors[0].ErrorMessage); // Das name must be at least 3 characters long
Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows
.NET Core netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.0 netstandard2.1
.NET Framework net461 net462 net463 net47 net471 net472 net48
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.1 381 5/14/2019

v1.0.1 - Renamed package so as to not collide with reserved FluentValidation prefix
v1.0.0 - Initial Release