{"id":370384,"date":"2024-05-21T04:24:00","date_gmt":"2024-05-21T04:24:00","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=370384"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=370384","title":{"rendered":"<span>\u041e\u0431\u0437\u043e\u0440 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 FluentValidation. \u0427\u0430\u0441\u0442\u044c 4. \u0421\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0430\u0445. \u041b\u043e\u043a\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/667\/356\/78d\/66735678dbd65665f5fcb9641f657b79.png\" width=\"1000\" height=\"1000\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/667\/356\/78d\/66735678dbd65665f5fcb9641f657b79.png\"\/><\/figure>\n<h2>\u0412\u044b\u0431\u043e\u0440 \u043b\u043e\u043a\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438<\/h2>\n<p>\u041f\u0440\u044f\u043c\u043e &#171;\u0438\u0437 \u043a\u043e\u0440\u043e\u0431\u043a\u0438&#187; \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u044b \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0430\u0445 \u043d\u0430 \u0440\u0430\u0437\u043d\u044b\u0445 \u044f\u0437\u044b\u043a\u0430\u0445 \u0434\u043b\u044f \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0445 \u0432\u0430\u043b\u0438\u0434\u0430\u0442\u043e\u0440\u043e\u0432. \u041f\u0435\u0440\u0435\u0432\u043e\u0434 \u043f\u043e\u0434\u0431\u0438\u0440\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0445 \u0441\u0432\u043e\u0439\u0441\u0442\u0432 <code>ValidatorOptions.Global.LanguageManager.Culture<\/code> (\u0432 \u043f\u0435\u0440\u0432\u0443\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u0435\u0441\u043b\u0438 \u0443\u043a\u0430\u0437\u0430\u043d\u043e) \u0438 <code>CultureInfo.CurrentUICulture<\/code> (\u0432\u043e \u0432\u0442\u043e\u0440\u0443\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c).<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u0440\u0443\u0441\u0441\u043a\u0443\u044e \u043b\u043e\u043a\u0430\u043b\u044c, \u043d\u0443\u0436\u043d\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0434\u043b\u044f <code>CultureInfo.CurrentUICulture<\/code> (\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0434\u043b\u044f <code>ValidatorOptions.Global.LanguageManager.Culture<\/code> \u043d\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u043e) :<\/p>\n<pre><code class=\"cs\">\/\/ \u041c\u043e\u0434\u0435\u043b\u044c \u043a\u043b\u0438\u0435\u043d\u0442\u0430 public class Customer {   \/\/ \u0424\u0430\u043c\u0438\u043b\u0438\u044f   public string? Surname { get; set; } }  \/\/ \u0412\u0430\u043b\u0438\u0434\u0430\u0442\u043e\u0440 \u0434\u043b\u044f \u043c\u043e\u0434\u0435\u043b\u0438 \u043a\u043b\u0438\u0435\u043d\u0442\u0430 public class CustomerValidator : AbstractValidator&lt;Customer> {   public CustomerValidator()   {     RuleFor(customer => customer.Surname)       .NotNull();   } }  static void Main(string[] args) {   \/\/ ru-RU - \u043a\u0443\u043b\u044c\u0442\u0443\u0440\u0430-\u0441\u0443\u0431\u043a\u0443\u043b\u044c\u0442\u0443\u0440\u0430, \u0444\u043e\u0440\u043c\u0430\u0442 RFC 4646   CultureInfo.CurrentUICulture = new CultureInfo(\"ru-RU\");    \/\/ \u0412\u0430\u043b\u0438\u0434\u0438\u0440\u0443\u0435\u043c, \u043a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u043e   var customer = new Customer { Surname = null };   var validator = new CustomerValidator();   var result = validator.Validate(customer);    Console.WriteLine(result.ToString(Environment.NewLine));   \/\/ \u0412\u044b\u0432\u0435\u0434\u0435\u0442 > \"'Surname' \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u043e.\"    \/\/ \u041c\u0435\u043d\u044f\u0435\u043c \u043d\u0430 \u0430\u043d\u0433\u043b\u043e\u044f\u0437\u044b\u0447\u043d\u0443\u044e \u043a\u0443\u043b\u044c\u0442\u0443\u0440\u0443   \/\/ en-US - \u043a\u0443\u043b\u044c\u0442\u0443\u0440\u0430-\u0441\u0443\u0431\u043a\u0443\u043b\u044c\u0442\u0443\u0440\u0430, \u0444\u043e\u0440\u043c\u0430\u0442 RFC 4646   CultureInfo.CurrentUICulture = new CultureInfo(\"en-US\");      \/\/ \u0412\u0430\u043b\u0438\u0434\u0438\u0440\u0443\u0435\u043c, \u043a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u043e   result = validator.Validate(customer);   Console.WriteLine(result.ToString(Environment.NewLine));   \/\/ \u0412\u044b\u0432\u0435\u0434\u0435\u0442 > \"'Surname' must not be empty.\" }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u043b\u043e\u043a\u0430\u043b\u044c \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 <code>ValidatorOptions.Global.LanguageManager.Culture<\/code>:<\/p>\n<pre><code class=\"cs\">\/\/ ... \u0442\u043e\u0442 \u0436\u0435 \u043a\u043e\u0434 \u0447\u0442\u043e \u0432\u044b\u0448\u0435  static void Main(string[] args) {   \/\/ ru-RU - \u043a\u0443\u043b\u044c\u0442\u0443\u0440\u0430-\u0441\u0443\u0431\u043a\u0443\u043b\u044c\u0442\u0443\u0440\u0430, \u0444\u043e\u0440\u043c\u0430\u0442 RFC 4646   ValidatorOptions.Global.LanguageManager.Culture = new CultureInfo(\"ru-RU\");   \/\/ fr - \u0434\u0432\u0443\u0437\u043d\u0430\u0447\u043d\u044b\u0439 \u043a\u043e\u0434 ISO 639 \u0432 \u043d\u0438\u0436\u043d\u0435\u043c \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0435   CultureInfo.CurrentUICulture = new CultureInfo(\"fr\");    \/\/ \u0412\u0430\u043b\u0438\u0434\u0438\u0440\u0443\u0435\u043c, \u043a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u043e   var customer = new Customer { Surname = null };   var validator = new CustomerValidator();   var result = validator.Validate(customer);    Console.WriteLine(result.ToString(Environment.NewLine));   \/\/ \u0412\u044b\u0432\u0435\u0434\u0435\u0442 > \"'Surname' \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u043e.\" (\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0430\u0441\u044c \u043a\u0443\u043b\u044c\u0442\u0443\u0440\u0430 ru-RU)    \/\/ en-US - \u043a\u0443\u043b\u044c\u0442\u0443\u0440\u0430-\u0441\u0443\u0431\u043a\u0443\u043b\u044c\u0442\u0443\u0440\u0430, \u0444\u043e\u0440\u043c\u0430\u0442 RFC 4646   CultureInfo.CurrentUICulture = new CultureInfo(\"en-US\");    \/\/ \u0412\u0430\u043b\u0438\u0434\u0438\u0440\u0443\u0435\u043c, \u043a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u043e   result = validator.Validate(customer);   Console.WriteLine(result.ToString(Environment.NewLine));   \/\/ \u0412\u044b\u0432\u0435\u0434\u0435\u0442 > \"'Surname' \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u043e.\" (\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0430\u0441\u044c \u043a\u0443\u043b\u044c\u0442\u0443\u0440\u0430 ru-RU) }<\/code><\/pre>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432 <code>ValidatorOptions.Global.LanguageManager.Culture<\/code> &#171;\u043f\u0435\u0440\u0435\u0431\u0438\u0432\u0430\u0435\u0442&#187; \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 <code>CultureInfo.CurrentUICulture<\/code> (\u0434\u043b\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 <strong>FluentValidation<\/strong>)<\/p>\n<h2>\u041e\u0442\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043b\u043e\u043a\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438<\/h2>\n<p>\u0427\u0442\u043e\u0431\u044b \u043e\u0442\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0432\u044b\u0431\u043e\u0440 \u043b\u043e\u043a\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0441\u0432\u043e\u0439\u0441\u0442\u0432 <code>ValidatorOptions.Global.LanguageManager.Culture<\/code> \u0438 <code>CultureInfo.CurrentUICulture<\/code>, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0437\u0430\u0434\u0430\u0442\u044c \u0432 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>false<\/code> \u0434\u043b\u044f \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 <code>ValidatorOptions.Global.LanguageManager.Enabled<\/code>:<\/p>\n<pre><code class=\"cs\">\/\/ ... \u0442\u043e\u0442 \u0436\u0435 \u043a\u043e\u0434 \u0447\u0442\u043e \u0432\u044b\u0448\u0435  static void Main(string[] args) {   \/\/ \u041e\u0442\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u0432\u044b\u0431\u043e\u0440 \u043b\u043e\u043a\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435   \/\/ \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f ValidatorOptions.Global.LanguageManager.Culture   \/\/ \u0438 CultureInfo.CurrentUICulture   ValidatorOptions.Global.LanguageManager.Enabled = false;   \/\/ ru-RU - \u043a\u0443\u043b\u044c\u0442\u0443\u0440\u0430-\u0441\u0443\u0431\u043a\u0443\u043b\u044c\u0442\u0443\u0440\u0430   CultureInfo.CurrentUICulture = new CultureInfo(\"ru-RU\");    \/\/ \u0412\u0430\u043b\u0438\u0434\u0438\u0440\u0443\u0435\u043c, \u043a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u043e   var customer = new Customer { Surname = null };   var validator = new CustomerValidator();   var result = validator.Validate(customer);    Console.WriteLine(result.ToString(Environment.NewLine));   \/\/ \u0412\u044b\u0432\u0435\u0434\u0435\u0442 > \"'Surname' must not be empty.\"    \/\/ \u041c\u0435\u043d\u044f\u0435\u043c \u043d\u0430 \u0430\u043d\u0433\u043b\u043e\u044f\u0437\u044b\u0447\u043d\u0443\u044e \u043a\u0443\u043b\u044c\u0442\u0443\u0440\u0443   \/\/ en-US - \u043a\u0443\u043b\u044c\u0442\u0443\u0440\u0430-\u0441\u0443\u0431\u043a\u0443\u043b\u044c\u0442\u0443\u0440\u0430   CultureInfo.CurrentUICulture = new CultureInfo(\"en-US\");    \/\/ \u0412\u0430\u043b\u0438\u0434\u0438\u0440\u0443\u0435\u043c, \u043a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u043e   result = validator.Validate(customer);   Console.WriteLine(result.ToString(Environment.NewLine));   \/\/ \u0412\u044b\u0432\u0435\u0434\u0435\u0442 > \"'Surname' must not be empty.\" }<\/code><\/pre>\n<p>\u0412\u0435\u0437\u0434\u0435 \u0431\u0443\u0434\u0435\u0442 \u0430\u043d\u0433\u043b\u043e\u044f\u0437\u044b\u0447\u043d\u0430\u044f \u043b\u043e\u043a\u0430\u043b\u044c.<\/p>\n<h2>\u041a\u0430\u0441\u0442\u043e\u043c\u043d\u0430\u044f \u043b\u043e\u043a\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0434\u043b\u044f \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0430\u0445 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e<\/h2>\n<p>\u0427\u0442\u043e\u0431\u044b \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u0442\u0435\u043a\u0441\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 (\u0447\u0430\u0441\u0442\u0438\u0447\u043d\u043e \u043b\u0438\u0431\u043e \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e), \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 <code>ILanguageManager<\/code>. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u043b\u044f \u0432\u0430\u043b\u0438\u0434\u0430\u0442\u043e\u0440\u0430 <code>NotNull<\/code> \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e <code>\"'{PropertyName}'\u00a0must\u00a0not\u00a0be\u00a0empty.\"<\/code>. \u0427\u0442\u043e\u0431\u044b \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u044d\u0442\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0432\u043e \u0432\u0441\u0435\u0445 \u043c\u0435\u0441\u0442\u0430\u0445 \u0433\u0434\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f <code>NotNull<\/code> \u0432\u0430\u043b\u0438\u0434\u0430\u0442\u043e\u0440, \u043d\u0443\u0436\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0439 <code>LanguageManager<\/code>:<\/p>\n<pre><code class=\"cs\">public class CustomRussianLanguageManager : FluentValidation.Resources.LanguageManager {   public CustomRussianLanguageManager()   {     \/\/ ru-RU - \u043b\u043e\u043a\u0430\u043b\u044c \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043f\u0435\u0440\u0435\u0432\u043e\u0434     \/\/ NotNullValidator - \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0432\u0430\u043b\u0438\u0434\u0430\u0442\u043e\u0440\u0430 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043f\u0435\u0440\u0435\u0432\u043e\u0434 (PropertyValidator)     \/\/ \u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 - \u0442\u0435\u043a\u0441\u0442 \u0432\u044b\u0432\u043e\u0434\u0438\u043c\u043e\u0433\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0435     AddTranslation(\"ru-RU\", \"NotNullValidator\", \"\u0421\u0432\u043e\u0439\u0441\u0442\u0432\u043e '{PropertyName}' \u043e\u0447\u0435\u043d\u044c \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043a \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044e.\");   } }<\/code><\/pre>\n<p>\u0427\u0442\u043e\u0431\u044b \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e, \u043d\u0443\u0436\u043d\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430\u0445 \u0434\u043b\u044f \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430  <code>ValidatorOptions.Global.LanguageManager<\/code>:<\/p>\n<pre><code class=\"cs\">\/\/ \u041c\u043e\u0434\u0435\u043b\u044c \u043a\u043b\u0438\u0435\u043d\u0442\u0430 public class Customer {   public string? Surname { get; set; }   public string? Forename { get; set; } }  \/\/ \u0412\u0430\u043b\u0438\u0434\u0430\u0442\u043e\u0440 \u0434\u043b\u044f \u043c\u043e\u0434\u0435\u043b\u0438 \u043a\u043b\u0438\u0435\u043d\u0442\u0430 public class CustomerValidator : AbstractValidator&lt;Customer> {   public CustomerValidator()   {     RuleFor(customer => customer.Surname)       .NotNull();      RuleFor(customer => customer.Forename)       .Null();   } }  static void Main(string[] args) {   \/\/ \u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0439 LanguageManager   ValidatorOptions.Global.LanguageManager = new CustomRussianLanguageManager();   CultureInfo.CurrentUICulture = new CultureInfo(\"ru-RU\");    \/\/ \u0412\u0430\u043b\u0438\u0434\u0438\u0440\u0443\u0435\u043c, \u043a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u043e   var customer = new Customer { Surname = null, Forename = \"\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\" };   var validator = new CustomerValidator();   var result = validator.Validate(customer);    Console.WriteLine(result.ToString(Environment.NewLine));   \/\/ \u0412\u044b\u0432\u0435\u0434\u0435\u0442 >   \/\/ \u0421\u0432\u043e\u0439\u0441\u0442\u0432\u043e 'Surname' \u043e\u0447\u0435\u043d\u044c \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043a \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044e.   \/\/ 'Forename' \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u043f\u0443\u0441\u0442\u044b\u043c.    \/\/ \u041c\u0435\u043d\u044f\u0435\u043c \u043b\u043e\u043a\u0430\u043b\u044c \u043d\u0430 en-US   CultureInfo.CurrentUICulture = new CultureInfo(\"en-US\");    \/\/ \u0412\u0430\u043b\u0438\u0434\u0438\u0440\u0443\u0435\u043c \u043a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u043e   result = validator.Validate(customer);   Console.WriteLine(result.ToString(Environment.NewLine));   \/\/ \u0412\u044b\u0432\u0435\u0434\u0435\u0442 >   \/\/ 'Surname' must not be empty.   \/\/ 'Forename' must be empty. }<\/code><\/pre>\n<p>\u0410 \u0432\u043e\u0442 \u0442\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0443\u0436\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0439 <code>LanguageManager<\/code> \u0434\u043b\u044f \u0440\u0443\u0441\u0441\u043a\u043e\u0439 \u043b\u043e\u043a\u0430\u043b\u0438:<\/p>\n<pre><code class=\"cs\">internal class RussianLanguage {   public const string Culture = \"ru\";    public static string GetTranslation(string key) => key switch   {       \"EmailValidator\" => \"'{PropertyName}' \u043d\u0435\u0432\u0435\u0440\u043d\u044b\u0439 email \u0430\u0434\u0440\u0435\u0441.\",       \"GreaterThanOrEqualValidator\" => \"'{PropertyName}' \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435 \u0438\u043b\u0438 \u0440\u0430\u0432\u043d\u043e '{ComparisonValue}'.\",       \"GreaterThanValidator\" => \"'{PropertyName}' \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435 '{ComparisonValue}'.\",       \"LengthValidator\" => \"'{PropertyName}' \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0434\u043b\u0438\u043d\u043e\u0439 \u043e\u0442 {MinLength} \u0434\u043e {MaxLength} \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432. \u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0445 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432: {TotalLength}.\",       \"MinimumLengthValidator\" => \"'{PropertyName}' \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0434\u043b\u0438\u043d\u043e\u0439 \u043d\u0435 \u043c\u0435\u043d\u0435\u0435 {MinLength} \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432. \u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0445 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432: {TotalLength}.\",       \"MaximumLengthValidator\" => \"'{PropertyName}' \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0434\u043b\u0438\u043d\u043e\u0439 \u043d\u0435 \u0431\u043e\u043b\u0435\u0435 {MaxLength} \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432. \u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0445 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432: {TotalLength}.\",       \"LessThanOrEqualValidator\" => \"'{PropertyName}' \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u043c\u0435\u043d\u044c\u0448\u0435 \u0438\u043b\u0438 \u0440\u0430\u0432\u043d\u043e '{ComparisonValue}'.\",       \"LessThanValidator\" => \"'{PropertyName}' \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u043c\u0435\u043d\u044c\u0448\u0435 '{ComparisonValue}'.\",       \"NotEmptyValidator\" => \"'{PropertyName}' \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u043e.\",       \"NotEqualValidator\" => \"'{PropertyName}' \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0440\u0430\u0432\u043d\u043e '{ComparisonValue}'.\",       \"NotNullValidator\" => \"'{PropertyName}' \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u043e.\",       \"PredicateValidator\" => \"\u041d\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u0435 \u0434\u043b\u044f '{PropertyName}'.\",       \"AsyncPredicateValidator\" => \"\u041d\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u0435 \u0434\u043b\u044f '{PropertyName}'.\",       \"RegularExpressionValidator\" => \"'{PropertyName}' \u0438\u043c\u0435\u0435\u0442 \u043d\u0435\u0432\u0435\u0440\u043d\u044b\u0439 \u0444\u043e\u0440\u043c\u0430\u0442.\",       \"EqualValidator\" => \"'{PropertyName}' \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0440\u0430\u0432\u043d\u043e '{ComparisonValue}'.\",       \"ExactLengthValidator\" => \"'{PropertyName}' \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0434\u043b\u0438\u043d\u043e\u0439 {MaxLength} \u0441\u0438\u043c\u0432\u043e\u043b\u0430(\u043e\u0432). \u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0445 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432: {TotalLength}.\",       \"InclusiveBetweenValidator\" => \"'{PropertyName}' \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0432 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0435 \u043e\u0442 {From} \u0434\u043e {To}. \u0412\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435: {PropertyValue}.\",       \"ExclusiveBetweenValidator\" => \"'{PropertyName}' \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0432 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0435 \u043e\u0442 {From} \u0434\u043e {To} (\u043d\u0435 \u0432\u043a\u043b\u044e\u0447\u0430\u044f \u044d\u0442\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f). \u0412\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435: {PropertyValue}.\",       \"CreditCardValidator\" => \"'{PropertyName}' \u043d\u0435\u0432\u0435\u0440\u043d\u044b\u0439 \u043d\u043e\u043c\u0435\u0440 \u043a\u0430\u0440\u0442\u044b.\",       \"ScalePrecisionValidator\" => \"'{PropertyName}' \u0434\u043e\u043b\u0436\u043d\u043e \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u043d\u0435 \u0431\u043e\u043b\u0435\u0435 {ExpectedPrecision} \u0446\u0438\u0444\u0440 \u0432\u0441\u0435\u0433\u043e, \u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 {ExpectedScale} \u0434\u0435\u0441\u044f\u0442\u0438\u0447\u043d\u044b\u0445 \u0437\u043d\u0430\u043a\u0430(\u043e\u0432). \u0412\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 {Digits} \u0446\u0438\u0444\u0440(\u044b) \u0432 \u0446\u0435\u043b\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u0438 {ActualScale} \u0434\u0435\u0441\u044f\u0442\u0438\u0447\u043d\u044b\u0445 \u0437\u043d\u0430\u043a\u0430(\u043e\u0432).\",       \"EmptyValidator\" => \"'{PropertyName}' \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u043f\u0443\u0441\u0442\u044b\u043c.\",       \"NullValidator\" => \"'{PropertyName}' \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u043f\u0443\u0441\u0442\u044b\u043c.\",       \"EnumValidator\" => \"'{PropertyName}' \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043d\u0435\u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 '{PropertyValue}'.\",       \/\/ Additional fallback messages used by clientside validation integration.       \"Length_Simple\" => \"'{PropertyName}' \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0434\u043b\u0438\u043d\u043e\u0439 \u043e\u0442 {MinLength} \u0434\u043e {MaxLength} \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432.\",       \"MinimumLength_Simple\" => \"'{PropertyName}' \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0434\u043b\u0438\u043d\u043e\u0439 \u043d\u0435 \u043c\u0435\u043d\u0435\u0435 {MinLength} \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432.\",       \"MaximumLength_Simple\" => \"'{PropertyName}' \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0434\u043b\u0438\u043d\u043e\u0439 \u043d\u0435 \u0431\u043e\u043b\u0435\u0435 {MaxLength} \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432.\",       \"ExactLength_Simple\" => \"'{PropertyName}' \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0434\u043b\u0438\u043d\u043e\u0439 {MaxLength} \u0441\u0438\u043c\u0432\u043e\u043b\u0430(\u043e\u0432).\",       \"InclusiveBetween_Simple\" => \"'{PropertyName}' \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0432 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0435 \u043e\u0442 {From} \u0434\u043e {To}.\",        _ => null,   }; }<\/code><\/pre>\n<h2>\u041b\u043e\u043a\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0445 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0430\u0445 \u0447\u0435\u0440\u0435\u0437 IStringLocalizer<\/h2>\n<p>\u0422\u0438\u043f <code>IStringLocalizer<\/code> \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0432 \u043f\u0430\u043a\u0435\u0442\u0435 <code>Microsoft.Extensions.Localization<\/code><\/p>\n<p>\u041f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u0432\u044b \u0443\u0436\u0435 \u0437\u043d\u0430\u043a\u043e\u043c\u044b \u043a\u0430\u043a \u0441 \u043d\u0438\u043c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c, \u0442. \u043a. \u043e\u043d \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0447\u0430\u0441\u0442\u044c\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 <strong>FluentValidation<\/strong>.<\/p>\n<p><strong>\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0430:<\/strong><\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/a12\/a3d\/cd3\/a12a3dcd3ce0b2994d27decb6d976ebd.png\" alt=\"\" title=\"\" width=\"260\" height=\"219\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/a12\/a3d\/cd3\/a12a3dcd3ce0b2994d27decb6d976ebd.png\"\/><\/figure>\n<p><strong>\u0421\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u0444\u0430\u0439\u043b\u0430 <\/strong><code>CustomerValidator.en.resx<\/code><strong>:<\/strong><\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/219\/d0e\/715\/219d0e715fd84f8182ceb96f951c09ea.png\" width=\"1745\" height=\"73\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/219\/d0e\/715\/219d0e715fd84f8182ceb96f951c09ea.png\"\/><\/figure>\n<p><strong>\u0421\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u0444\u0430\u0439\u043b\u0430 <\/strong><code>CustomerValidator.ru.resx<\/code><strong>:<\/strong><\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/d67\/a0c\/42d\/d67a0c42d0ec5b80f5468bcc99f337ae.png\" width=\"1750\" height=\"78\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d67\/a0c\/42d\/d67a0c42d0ec5b80f5468bcc99f337ae.png\"\/><\/figure>\n<p><strong>\u0412\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c:<\/strong><\/p>\n<pre><code class=\"cs\">using FluentValidation; using FluentValidationTests.Models; using FluentValidationTests.Validators; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Localization; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; using System.Globalization;  \/\/ \u041c\u043e\u0434\u0435\u043b\u044c \u043a\u043b\u0438\u0435\u043d\u0442\u0430 public class Customer {   \/\/ \u0424\u0430\u043c\u0438\u043b\u0438\u044f   public string? Surname { get; set; } }  \/\/ \u0412\u0430\u043b\u0438\u0434\u0430\u0442\u043e\u0440 \u0434\u043b\u044f \u043c\u043e\u0434\u0435\u043b\u0438 \u043a\u043b\u0438\u0435\u043d\u0442\u0430 public class CustomerValidator : AbstractValidator&lt;Customer> {   public CustomerValidator(IStringLocalizer&lt;CustomerValidator> localizer)   {     \/\/ \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c IStringLocalizer&lt;CustomerValidator> \u0432\u043d\u0443\u0442\u0440\u0438 \u043c\u0435\u0442\u043e\u0434\u0430 WithMessage     \/\/ SurnameNotNull - \u044d\u0442\u043e \u043a\u043b\u044e\u0447, \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u043c\u043e\u0436\u0435\u043c \u043d\u0430\u0439\u0442\u0438 \u043d\u0443\u0436\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435     \/\/ \u0432 \u0444\u0430\u0439\u043b\u0435 \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432     RuleFor(customer => customer.Surname)       .NotNull()         .WithMessage(localizer[\"SurnameNotNull\"]);   } }  static void Main(string[] args) {   \/\/ \u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u043a\u0443\u043b\u044c\u0442\u0443\u0440\u0443 \"en\", \u043d\u0430 \u0435\u0451 \u043e\u0441\u043d\u043e\u0432\u0435 \u043f\u043e\u0434\u0431\u0438\u0440\u0430\u0435\u0442\u0441\u044f \u043d\u0443\u0436\u043d\u044b\u0439   \/\/ \u0444\u0430\u0439\u043b \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432 \u0438\u0437 \u043f\u0430\u043f\u043a\u0438 Resources   CultureInfo.CurrentUICulture = new CultureInfo(\"en\");    \/\/ \u0420\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u043c IStringLocalizer (\u0441\u0434\u0435\u043b\u0430\u043d\u043e \u0447\u0435\u0440\u0435\u0437 DI)   var services = new ServiceCollection();    services.AddSingleton&lt;ILoggerFactory>(NullLoggerFactory.Instance);   services.AddLocalization(opts => opts.ResourcesPath = \"Resources\");    var provider = services.BuildServiceProvider();    \/\/ \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0438\u0437 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430 DI IStringLocalizer \u0434\u043b\u044f CustomerValidator   var localizer = provider.GetRequiredService&lt;IStringLocalizer&lt;CustomerValidator>>();    \/\/ \u0412\u0430\u043b\u0438\u0434\u0438\u0440\u0443\u0435\u043c, \u043a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u043e   var customer = new Customer { Surname = null };   \/\/ \u041f\u0435\u0440\u0435\u0434\u0430\u0451\u043c IStringLocalizer \u0432 \u0432\u0430\u043b\u0438\u0434\u0430\u0442\u043e\u0440   var validator = new CustomerValidator(localizer);   var result = validator.Validate(customer);    Console.WriteLine(result.ToString(Environment.NewLine));   \/\/ \u0412\u044b\u0432\u0435\u0434\u0435\u0442 > \"\u0410\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u0438\u0439 \u044f\u0437\u044b\u043a, \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 'Surname'\"   \/\/ \u0438\u0437 \u0444\u0430\u0439\u043b\u0430 (\/Resources\/Validators\/CustomerValidator.en.resx) }<\/code><\/pre>\n<h2>\u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u0441 \u043b\u043e\u043a\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0435\u0439<\/h2>\n<p>\u0412 \u043f\u0440\u043e\u0448\u043b\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u0431\u044b\u043b \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0439: <a href=\"https:\/\/habr.com\/ru\/articles\/798961\/#comment_26593563\" rel=\"noopener noreferrer nofollow\">https:\/\/habr.com\/ru\/articles\/798961\/#comment_26593563<\/a><\/p>\n<p>\u041c\u044b \u0445\u043e\u0442\u0438\u043c \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u044c \u0434\u0430\u0442\u044b \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 <code>en<\/code> \u043b\u043e\u043a\u0430\u043b\u0438 \u0432 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f\u0445 \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0430\u0445, \u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u043c\u0438 \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438:<\/p>\n<pre><code class=\"cs\">\/\/ \u041c\u043e\u0434\u0435\u043b\u044c \u043a\u043b\u0438\u0435\u043d\u0442\u0430 public class Customer {   public string? Surname { get; set; } }  \/\/ \u0412\u0430\u043b\u0438\u0434\u0430\u0442\u043e\u0440\u0430 \u0434\u043b\u044f \u043c\u043e\u0434\u0435\u043b\u0438 \u043a\u043b\u0438\u0435\u043d\u0442\u0430 public class CustomerValidator : AbstractValidator&lt;Customer> {   public CustomerValidator()   {     \/\/ \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0442\u0435\u043a\u0443\u0449\u0443\u044e \u0434\u0430\u0442\u0443 \u0438 \u0432\u0440\u0435\u043c\u044f \u043f\u043e UTC \u0432 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0438 \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0435     RuleFor(customer => customer.Surname)       .NotNull()         .WithMessage($\"{DateTime.UtcNow}\");   } }  static void Main(string[] args) {   \/\/ \u041f\u0440\u043e\u0431\u0443\u0435\u043c \u043f\u0435\u0440\u0432\u044b\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u043b\u043e\u043a\u0430\u043b\u044c   CultureInfo.CurrentUICulture = new CultureInfo(\"en\");    \/\/ \u0412\u0430\u043b\u0438\u0434\u0438\u0440\u0443\u0435\u043c \u043a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u043e   var customer = new Customer { Surname = null };   var validator = new CustomerValidator();   var result = validator.Validate(customer);    Console.WriteLine(result.ToString(Environment.NewLine));   \/\/ \u0412\u044b\u0432\u043e\u0434\u0438\u0442 > \"7.03.2024 5:31:55\" (\u043b\u043e\u043a\u0430\u043b\u044c ru-RU)    \/\/ \u041f\u0440\u043e\u0431\u0443\u0435\u043c \u0432\u0442\u043e\u0440\u044b\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u043b\u043e\u043a\u0430\u043b\u044c   ValidatorOptions.Global.LanguageManager.Culture = new CultureInfo(\"en\");      result = validator.Validate(customer);   Console.WriteLine(result.ToString(Environment.NewLine));   \/\/ \u0412\u044b\u0432\u043e\u0434\u0438\u0442 > \"7.03.2024 5:31:55\" (\u043b\u043e\u043a\u0430\u043b\u044c ru-RU) }<\/code><\/pre>\n<p>\u041e\u0431\u0430 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430 \u043d\u0435 \u0434\u0430\u043b\u0438 \u043d\u0430\u043c \u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u043f\u0440\u0438 \u043b\u043e\u043a\u0430\u043b\u0438 <code>en<\/code>.<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u044d\u0442\u0443 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443, \u043d\u0443\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e <code>CultureInfo.CurrentCulture<\/code>:<\/p>\n<pre><code class=\"cs\">public class Customer {   public string? Surname { get; set; }   public string? Forename { get; set; } }  public class CustomerValidator : AbstractValidator&lt;Customer> {   public CustomerValidator()   {     RuleFor(customer => customer.Surname)       .NotNull()         .WithMessage($\"{DateTime.UtcNow}\");      RuleFor(customer => customer.Forename)       .Null();   } }  static void Main(string[] args) {   CultureInfo.CurrentCulture = new CultureInfo(\"en\");    var customer = new Customer { Surname = null, Forename = \"\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\" };   var validator = new CustomerValidator();   var result = validator.Validate(customer);    Console.WriteLine(result.ToString(Environment.NewLine));   \/\/ \u0412\u044b\u0432\u043e\u0434\u0438\u0442 >   \/\/ 3\/7\/2024 5:40:26 AM   \/\/ 'Forename' \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u043f\u0443\u0441\u0442\u044b\u043c. }<\/code><\/pre>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u043b\u043e\u043a\u0430\u043b\u044c \u0434\u043b\u044f \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0430\u0445 \u043e\u0441\u0442\u0430\u043b\u0430\u0441\u044c <code>ru-RU<\/code>. \u0427\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u043d\u0430 \u043d\u0443\u0436\u043d\u0443\u044e \u043b\u043e\u043a\u0430\u043b\u044c, \u043d\u0443\u0436\u043d\u043e \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u043f\u0438\u0441\u0430\u0442\u044c:<\/p>\n<pre><code class=\"cs\">CultureInfo.CurrentUICulture = new CultureInfo(\"en\");<\/code><\/pre>\n<p>\u0438\u043b\u0438<\/p>\n<pre><code class=\"cs\">ValidatorOptions.Global.LanguageManager.Culture = new CultureInfo(\"en\");<\/code><\/pre>\n<p>\u2190 <a href=\"https:\/\/habr.com\/ru\/articles\/798961\/\" rel=\"noopener noreferrer nofollow\">\u041f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0430\u044f \u0447\u0430\u0441\u0442\u044c<\/a> <a href=\"https:\/\/habr.com\/ru\/articles\/799173\/\" rel=\"noopener noreferrer nofollow\">\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u0447\u0430\u0441\u0442\u044c<\/a> \u2192<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/799109\/\"> https:\/\/habr.com\/ru\/articles\/799109\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><\/figure>\n<h2>\u0412\u044b\u0431\u043e\u0440 \u043b\u043e\u043a\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438<\/h2>\n<p>\u041f\u0440\u044f\u043c\u043e &#171;\u0438\u0437 \u043a\u043e\u0440\u043e\u0431\u043a\u0438&#187; \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u044b \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0430\u0445 \u043d\u0430 \u0440\u0430\u0437\u043d\u044b\u0445 \u044f\u0437\u044b\u043a\u0430\u0445 \u0434\u043b\u044f \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0445 \u0432\u0430\u043b\u0438\u0434\u0430\u0442\u043e\u0440\u043e\u0432. \u041f\u0435\u0440\u0435\u0432\u043e\u0434 \u043f\u043e\u0434\u0431\u0438\u0440\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0445 \u0441\u0432\u043e\u0439\u0441\u0442\u0432 <code>ValidatorOptions.Global.LanguageManager.Culture<\/code> (\u0432 \u043f\u0435\u0440\u0432\u0443\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u0435\u0441\u043b\u0438 \u0443\u043a\u0430\u0437\u0430\u043d\u043e) \u0438 <code>CultureInfo.CurrentUICulture<\/code> (\u0432\u043e \u0432\u0442\u043e\u0440\u0443\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c).<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u0440\u0443\u0441\u0441\u043a\u0443\u044e \u043b\u043e\u043a\u0430\u043b\u044c, \u043d\u0443\u0436\u043d\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0434\u043b\u044f <code>CultureInfo.CurrentUICulture<\/code> (\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0434\u043b\u044f <code>ValidatorOptions.Global.LanguageManager.Culture<\/code> \u043d\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u043e) :<\/p>\n<pre><code class=\"cs\">\/\/ \u041c\u043e\u0434\u0435\u043b\u044c \u043a\u043b\u0438\u0435\u043d\u0442\u0430 public class Customer {   \/\/ \u0424\u0430\u043c\u0438\u043b\u0438\u044f   public string? Surname { get; set; } }  \/\/ \u0412\u0430\u043b\u0438\u0434\u0430\u0442\u043e\u0440 \u0434\u043b\u044f \u043c\u043e\u0434\u0435\u043b\u0438 \u043a\u043b\u0438\u0435\u043d\u0442\u0430 public class CustomerValidator : AbstractValidator&lt;Customer> {   public CustomerValidator()   {     RuleFor(customer => customer.Surname)       .NotNull();   } }  static void Main(string[] args) {   \/\/ ru-RU - \u043a\u0443\u043b\u044c\u0442\u0443\u0440\u0430-\u0441\u0443\u0431\u043a\u0443\u043b\u044c\u0442\u0443\u0440\u0430, \u0444\u043e\u0440\u043c\u0430\u0442 RFC 4646   CultureInfo.CurrentUICulture = new CultureInfo(\"ru-RU\");    \/\/ \u0412\u0430\u043b\u0438\u0434\u0438\u0440\u0443\u0435\u043c, \u043a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u043e   var customer = new Customer { Surname = null };   var validator = new CustomerValidator();   var result = validator.Validate(customer);    Console.WriteLine(result.ToString(Environment.NewLine));   \/\/ \u0412\u044b\u0432\u0435\u0434\u0435\u0442 > \"'Surname' \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u043e.\"    \/\/ \u041c\u0435\u043d\u044f\u0435\u043c \u043d\u0430 \u0430\u043d\u0433\u043b\u043e\u044f\u0437\u044b\u0447\u043d\u0443\u044e \u043a\u0443\u043b\u044c\u0442\u0443\u0440\u0443   \/\/ en-US - \u043a\u0443\u043b\u044c\u0442\u0443\u0440\u0430-\u0441\u0443\u0431\u043a\u0443\u043b\u044c\u0442\u0443\u0440\u0430, \u0444\u043e\u0440\u043c\u0430\u0442 RFC 4646   CultureInfo.CurrentUICulture = new CultureInfo(\"en-US\");      \/\/ \u0412\u0430\u043b\u0438\u0434\u0438\u0440\u0443\u0435\u043c, \u043a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u043e   result = validator.Validate(customer);   Console.WriteLine(result.ToString(Environment.NewLine));   \/\/ \u0412\u044b\u0432\u0435\u0434\u0435\u0442 > \"'Surname' must not be empty.\" }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u043b\u043e\u043a\u0430\u043b\u044c \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 <code>ValidatorOptions.Global.LanguageManager.Culture<\/code>:<\/p>\n<pre><code class=\"cs\">\/\/ ... \u0442\u043e\u0442 \u0436\u0435 \u043a\u043e\u0434 \u0447\u0442\u043e \u0432\u044b\u0448\u0435  static void Main(string[] args) {   \/\/ ru-RU - \u043a\u0443\u043b\u044c\u0442\u0443\u0440\u0430-\u0441\u0443\u0431\u043a\u0443\u043b\u044c\u0442\u0443\u0440\u0430, \u0444\u043e\u0440\u043c\u0430\u0442 RFC 4646   ValidatorOptions.Global.LanguageManager.Culture = new CultureInfo(\"ru-RU\");   \/\/ fr - \u0434\u0432\u0443\u0437\u043d\u0430\u0447\u043d\u044b\u0439 \u043a\u043e\u0434 ISO 639 \u0432 \u043d\u0438\u0436\u043d\u0435\u043c \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0435   CultureInfo.CurrentUICulture = new CultureInfo(\"fr\");    \/\/ \u0412\u0430\u043b\u0438\u0434\u0438\u0440\u0443\u0435\u043c, \u043a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u043e   var customer = new Customer { Surname = null };   var validator = new CustomerValidator();   var result = validator.Validate(customer);    Console.WriteLine(result.ToString(Environment.NewLine));   \/\/ \u0412\u044b\u0432\u0435\u0434\u0435\u0442 > \"'Surname' \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u043e.\" (\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0430\u0441\u044c \u043a\u0443\u043b\u044c\u0442\u0443\u0440\u0430 ru-RU)    \/\/ en-US - \u043a\u0443\u043b\u044c\u0442\u0443\u0440\u0430-\u0441\u0443\u0431\u043a\u0443\u043b\u044c\u0442\u0443\u0440\u0430, \u0444\u043e\u0440\u043c\u0430\u0442 RFC 4646   CultureInfo.CurrentUICulture = new CultureInfo(\"en-US\");    \/\/ \u0412\u0430\u043b\u0438\u0434\u0438\u0440\u0443\u0435\u043c, \u043a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u043e   result = validator.Validate(customer);   Console.WriteLine(result.ToString(Environment.NewLine));   \/\/ \u0412\u044b\u0432\u0435\u0434\u0435\u0442 > \"'Surname' \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u043e.\" (\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0430\u0441\u044c \u043a\u0443\u043b\u044c\u0442\u0443\u0440\u0430 ru-RU) }<\/code><\/pre>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432 <code>ValidatorOptions.Global.LanguageManager.Culture<\/code> &#171;\u043f\u0435\u0440\u0435\u0431\u0438\u0432\u0430\u0435\u0442&#187; \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 <code>CultureInfo.CurrentUICulture<\/code> (\u0434\u043b\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 <strong>FluentValidation<\/strong>)<\/p>\n<h2>\u041e\u0442\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043b\u043e\u043a\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438<\/h2>\n<p>\u0427\u0442\u043e\u0431\u044b \u043e\u0442\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0432\u044b\u0431\u043e\u0440 \u043b\u043e\u043a\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0441\u0432\u043e\u0439\u0441\u0442\u0432 <code>ValidatorOptions.Global.LanguageManager.Culture<\/code> \u0438 <code>CultureInfo.CurrentUICulture<\/code>, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0437\u0430\u0434\u0430\u0442\u044c \u0432 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>false<\/code> \u0434\u043b\u044f \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 <code>ValidatorOptions.Global.LanguageManager.Enabled<\/code>:<\/p>\n<pre><code class=\"cs\">\/\/ ... \u0442\u043e\u0442 \u0436\u0435 \u043a\u043e\u0434 \u0447\u0442\u043e \u0432\u044b\u0448\u0435  static void Main(string[] args) {   \/\/ \u041e\u0442\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u0432\u044b\u0431\u043e\u0440 \u043b\u043e\u043a\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435   \/\/ \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f ValidatorOptions.Global.LanguageManager.Culture   \/\/ \u0438 CultureInfo.CurrentUICulture   ValidatorOptions.Global.LanguageManager.Enabled = false;   \/\/ ru-RU - \u043a\u0443\u043b\u044c\u0442\u0443\u0440\u0430-\u0441\u0443\u0431\u043a\u0443\u043b\u044c\u0442\u0443\u0440\u0430   CultureInfo.CurrentUICulture = new CultureInfo(\"ru-RU\");    \/\/ \u0412\u0430\u043b\u0438\u0434\u0438\u0440\u0443\u0435\u043c, \u043a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u043e   var customer = new Customer { Surname = null };   var validator = new CustomerValidator();   var result = validator.Validate(customer);    Console.WriteLine(result.ToString(Environment.NewLine));   \/\/ \u0412\u044b\u0432\u0435\u0434\u0435\u0442 > \"'Surname' must not be empty.\"    \/\/ \u041c\u0435\u043d\u044f\u0435\u043c \u043d\u0430 \u0430\u043d\u0433\u043b\u043e\u044f\u0437\u044b\u0447\u043d\u0443\u044e \u043a\u0443\u043b\u044c\u0442\u0443\u0440\u0443   \/\/ en-US - \u043a\u0443\u043b\u044c\u0442\u0443\u0440\u0430-\u0441\u0443\u0431\u043a\u0443\u043b\u044c\u0442\u0443\u0440\u0430   CultureInfo.CurrentUICulture = new CultureInfo(\"en-US\");    \/\/ \u0412\u0430\u043b\u0438\u0434\u0438\u0440\u0443\u0435\u043c, \u043a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u043e   result = validator.Validate(customer);   Console.WriteLine(result.ToString(Environment.NewLine));   \/\/ \u0412\u044b\u0432\u0435\u0434\u0435\u0442 > \"'Surname' must not be empty.\" }<\/code><\/pre>\n<p>\u0412\u0435\u0437\u0434\u0435 \u0431\u0443\u0434\u0435\u0442 \u0430\u043d\u0433\u043b\u043e\u044f\u0437\u044b\u0447\u043d\u0430\u044f \u043b\u043e\u043a\u0430\u043b\u044c.<\/p>\n<h2>\u041a\u0430\u0441\u0442\u043e\u043c\u043d\u0430\u044f \u043b\u043e\u043a\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0434\u043b\u044f \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0430\u0445 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e<\/h2>\n<p>\u0427\u0442\u043e\u0431\u044b \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u0442\u0435\u043a\u0441\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 (\u0447\u0430\u0441\u0442\u0438\u0447\u043d\u043e \u043b\u0438\u0431\u043e \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e), \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 <code>ILanguageManager<\/code>. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u043b\u044f \u0432\u0430\u043b\u0438\u0434\u0430\u0442\u043e\u0440\u0430 <code>NotNull<\/code> \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e <code>\"'{PropertyName}'\u00a0must\u00a0not\u00a0be\u00a0empty.\"<\/code>. \u0427\u0442\u043e\u0431\u044b \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u044d\u0442\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0432\u043e \u0432\u0441\u0435\u0445 \u043c\u0435\u0441\u0442\u0430\u0445 \u0433\u0434\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f <code>NotNull<\/code> \u0432\u0430\u043b\u0438\u0434\u0430\u0442\u043e\u0440, \u043d\u0443\u0436\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0439 <code>LanguageManager<\/code>:<\/p>\n<pre><code class=\"cs\">public class CustomRussianLanguageManager : FluentValidation.Resources.LanguageManager {   public CustomRussianLanguageManager()   {     \/\/ ru-RU - \u043b\u043e\u043a\u0430\u043b\u044c \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043f\u0435\u0440\u0435\u0432\u043e\u0434     \/\/ NotNullValidator - \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0432\u0430\u043b\u0438\u0434\u0430\u0442\u043e\u0440\u0430 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043f\u0435\u0440\u0435\u0432\u043e\u0434 (PropertyValidator)     \/\/ \u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 - \u0442\u0435\u043a\u0441\u0442 \u0432\u044b\u0432\u043e\u0434\u0438\u043c\u043e\u0433\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0435     AddTranslation(\"ru-RU\", \"NotNullValidator\", \"\u0421\u0432\u043e\u0439\u0441\u0442\u0432\u043e '{PropertyName}' \u043e\u0447\u0435\u043d\u044c \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043a \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044e.\");   } }<\/code><\/pre>\n<p>\u0427\u0442\u043e\u0431\u044b \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e, \u043d\u0443\u0436\u043d\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430\u0445 \u0434\u043b\u044f \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430  <code>ValidatorOptions.Global.LanguageManager<\/code>:<\/p>\n<pre><code class=\"cs\">\/\/ \u041c\u043e\u0434\u0435\u043b\u044c \u043a\u043b\u0438\u0435\u043d\u0442\u0430 public class Customer {   public string? Surname { get; set; }   public string? Forename { get; set; } }  \/\/ \u0412\u0430\u043b\u0438\u0434\u0430\u0442\u043e\u0440 \u0434\u043b\u044f \u043c\u043e\u0434\u0435\u043b\u0438 \u043a\u043b\u0438\u0435\u043d\u0442\u0430 public class CustomerValidator : AbstractValidator&lt;Customer> {   public CustomerValidator()   {     RuleFor(customer => customer.Surname)       .NotNull();      RuleFor(customer => customer.Forename)       .Null();   } }  static void Main(string[] args) {   \/\/ \u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0439 LanguageManager   ValidatorOptions.Global.LanguageManager = new CustomRussianLanguageManager();   CultureInfo.CurrentUICulture = new CultureInfo(\"ru-RU\");    \/\/ \u0412\u0430\u043b\u0438\u0434\u0438\u0440\u0443\u0435\u043c, \u043a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u043e   var customer = new Customer { Surname = null, Forename = \"\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\" };   var validator = new CustomerValidator();   var result = validator.Validate(customer);    Console.WriteLine(result.ToString(Environment.NewLine));   \/\/ \u0412\u044b\u0432\u0435\u0434\u0435\u0442 >   \/\/ \u0421\u0432\u043e\u0439\u0441\u0442\u0432\u043e 'Surname' \u043e\u0447\u0435\u043d\u044c \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043a \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044e.   \/\/ 'Forename' \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u043f\u0443\u0441\u0442\u044b\u043c.    \/\/ \u041c\u0435\u043d\u044f\u0435\u043c \u043b\u043e\u043a\u0430\u043b\u044c \u043d\u0430 en-US   CultureInfo.CurrentUICulture = new CultureInfo(\"en-US\");    \/\/ \u0412\u0430\u043b\u0438\u0434\u0438\u0440\u0443\u0435\u043c \u043a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u043e   result = validator.Validate(customer);   Console.WriteLine(result.ToString(Environment.NewLine));   \/\/ \u0412\u044b\u0432\u0435\u0434\u0435\u0442 >   \/\/ 'Surname' must not be empty.   \/\/ 'Forename' must be empty. }<\/code><\/pre>\n<p>\u0410 \u0432\u043e\u0442 \u0442\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0443\u0436\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0439 <code>LanguageManager<\/code> \u0434\u043b\u044f \u0440\u0443\u0441\u0441\u043a\u043e\u0439 \u043b\u043e\u043a\u0430\u043b\u0438:<\/p>\n<pre><code class=\"cs\">internal class RussianLanguage {   public const string Culture = \"ru\";    public static string GetTranslation(string key) => key switch   {       \"EmailValidator\" => \"'{PropertyName}' \u043d\u0435\u0432\u0435\u0440\u043d\u044b\u0439 email \u0430\u0434\u0440\u0435\u0441.\",       \"GreaterThanOrEqualValidator\" => \"'{PropertyName}' \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435 \u0438\u043b\u0438 \u0440\u0430\u0432\u043d\u043e '{ComparisonValue}'.\",       \"GreaterThanValidator\" => \"'{PropertyName}' \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435 '{ComparisonValue}'.\",       \"LengthValidator\" => \"'{PropertyName}' \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0434\u043b\u0438\u043d\u043e\u0439 \u043e\u0442 {MinLength} \u0434\u043e {MaxLength} \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432. \u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0445 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432: {TotalLength}.\",       \"MinimumLengthValidator\" => \"'{PropertyName}' \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0434\u043b\u0438\u043d\u043e\u0439 \u043d\u0435 \u043c\u0435\u043d\u0435\u0435 {MinLength} \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432. \u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0445 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432: {TotalLength}.\",       \"MaximumLengthValidator\" => \"'{PropertyName}' \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0434\u043b\u0438\u043d\u043e\u0439 \u043d\u0435 \u0431\u043e\u043b\u0435\u0435 {MaxLength} \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432. \u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0445 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432: {TotalLength}.\",       \"LessThanOrEqualValidator\" => \"'{PropertyName}' \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u043c\u0435\u043d\u044c\u0448\u0435 \u0438\u043b\u0438 \u0440\u0430\u0432\u043d\u043e '{ComparisonValue}'.\",       \"LessThanValidator\" => \"'{PropertyName}' \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u043c\u0435\u043d\u044c\u0448\u0435 '{ComparisonValue}'.\",       \"NotEmptyValidator\" => \"'{PropertyName}' \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u043e.\",       \"NotEqualValidator\" => \"'{PropertyName}' \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0440\u0430\u0432\u043d\u043e '{ComparisonValue}'.\",       \"NotNullValidator\" => \"'{PropertyName}' \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u043e.\",       \"PredicateValidator\" => \"\u041d\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u0435 \u0434\u043b\u044f '{PropertyName}'.\",       \"AsyncPredicateValidator\" => \"\u041d\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u0435 \u0434\u043b\u044f '{PropertyName}'.\",       \"RegularExpressionValidator\" => \"'{PropertyName}' \u0438\u043c\u0435\u0435\u0442 \u043d\u0435\u0432\u0435\u0440\u043d\u044b\u0439 \u0444\u043e\u0440\u043c\u0430\u0442.\",       \"EqualValidator\" => \"'{PropertyName}' \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0440\u0430\u0432\u043d\u043e '{ComparisonValue}'.\",       \"ExactLengthValidator\" => \"'{PropertyName}' \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0434\u043b\u0438\u043d\u043e\u0439 {MaxLength} \u0441\u0438\u043c\u0432\u043e\u043b\u0430(\u043e\u0432). \u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0445 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432: {TotalLength}.\",       \"InclusiveBetweenValidator\" => \"'{PropertyName}' \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0432 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0435 \u043e\u0442 {From} \u0434\u043e {To}. \u0412\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435: {PropertyValue}.\",       \"ExclusiveBetweenValidator\" => \"'{PropertyName}' \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0432 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0435 \u043e\u0442 {From} \u0434\u043e {To} (\u043d\u0435 \u0432\u043a\u043b\u044e\u0447\u0430\u044f \u044d\u0442\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f). \u0412\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435: {PropertyValue}.\",       \"CreditCardValidator\" => \"'{PropertyName}' \u043d\u0435\u0432\u0435\u0440\u043d\u044b\u0439 \u043d\u043e\u043c\u0435\u0440 \u043a\u0430\u0440\u0442\u044b.\",       \"ScalePrecisionValidator\" => \"'{PropertyName}' \u0434\u043e\u043b\u0436\u043d\u043e \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u043d\u0435 \u0431\u043e\u043b\u0435\u0435 {ExpectedPrecision} \u0446\u0438\u0444\u0440 \u0432\u0441\u0435\u0433\u043e, \u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 {ExpectedScale} \u0434\u0435\u0441\u044f\u0442\u0438\u0447\u043d\u044b\u0445 \u0437\u043d\u0430\u043a\u0430(\u043e\u0432). \u0412\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 {Digits} \u0446\u0438\u0444\u0440(\u044b) \u0432 \u0446\u0435\u043b\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u0438 {ActualScale} \u0434\u0435\u0441\u044f\u0442\u0438\u0447\u043d\u044b\u0445 \u0437\u043d\u0430\u043a\u0430(\u043e\u0432).\",       \"EmptyValidator\" => \"'{PropertyName}' \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u043f\u0443\u0441\u0442\u044b\u043c.\",       \"NullValidator\" => \"'{PropertyName}' \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u043f\u0443\u0441\u0442\u044b\u043c.\",       \"EnumValidator\" => \"'{PropertyName}' \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043d\u0435\u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 '{PropertyValue}'.\",       \/\/ Additional fallback messages used by clientside validation integration.       \"Length_Simple\" => \"'{PropertyName}' \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0434\u043b\u0438\u043d\u043e\u0439 \u043e\u0442 {MinLength} \u0434\u043e {MaxLength} \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432.\",       \"MinimumLength_Simple\" => \"'{PropertyName}' \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0434\u043b\u0438\u043d\u043e\u0439 \u043d\u0435 \u043c\u0435\u043d\u0435\u0435 {MinLength} \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432.\",       \"MaximumLength_Simple\" => \"'{PropertyName}' \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0434\u043b\u0438\u043d\u043e\u0439 \u043d\u0435 \u0431\u043e\u043b\u0435\u0435 {MaxLength} \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432.\",       \"ExactLength_Simple\" => \"'{PropertyName}' \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0434\u043b\u0438\u043d\u043e\u0439 {MaxLength} \u0441\u0438\u043c\u0432\u043e\u043b\u0430(\u043e\u0432).\",       \"InclusiveBetween_Simple\" => \"'{PropertyName}' \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0432 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0435 \u043e\u0442 {From} \u0434\u043e {To}.\",        _ => null,   }; }<\/code><\/pre>\n<h2>\u041b\u043e\u043a\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0445 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0430\u0445 \u0447\u0435\u0440\u0435\u0437 IStringLocalizer<\/h2>\n<p>\u0422\u0438\u043f <code>IStringLocalizer<\/code> \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0432 \u043f\u0430\u043a\u0435\u0442\u0435 <code>Microsoft.Extensions.Localization<\/code><\/p>\n<p>\u041f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u0432\u044b \u0443\u0436\u0435 \u0437\u043d\u0430\u043a\u043e\u043c\u044b \u043a\u0430\u043a \u0441 \u043d\u0438\u043c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c, \u0442. \u043a. \u043e\u043d \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0447\u0430\u0441\u0442\u044c\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 <strong>FluentValidation<\/strong>.<\/p>\n<p><strong>\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0430:<\/strong><\/p>\n<figure class=\"\"><\/figure>\n<p><strong>\u0421\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u0444\u0430\u0439\u043b\u0430 <\/strong><code>CustomerValidator.en.resx<\/code><strong>:<\/strong><\/p>\n<figure class=\"full-width\"><\/figure>\n<p><strong>\u0421\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u0444\u0430\u0439\u043b\u0430 <\/strong><code>CustomerValidator.ru.resx<\/code><strong>:<\/strong><\/p>\n<figure class=\"full-width\"><\/figure>\n<p><strong>\u0412\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c:<\/strong><\/p>\n<pre><code class=\"cs\">using FluentValidation; using FluentValidationTests.Models;<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-370384","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/370384","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=370384"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/370384\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=370384"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=370384"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=370384"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}