damienbod / AspNetCoreLocalization

Localization.SqlLocalizer & ASP.NET Core MVC Localization Examples
http://damienbod.com/2015/10/21/asp-net-5-mvc-6-localization/
MIT License
251 stars 101 forks source link

DataAnnotations string.Format doesn't work #67

Closed suatsuphi closed 3 years ago

suatsuphi commented 4 years ago

Hi, Display Name doesn't work on errormessage {0} exmaple

public class RegisterViewModel
{
    [Required(ErrorMessage = "The {0} field is required.")]
    [EmailAddress(ErrorMessage = "The {0} field is not a valid email address.")]
    [Display(Name = "Email")]
    public string Email { get; set; }

    [Required(ErrorMessage = "The {0} field is required.")]
    [StringLength(8, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
    [DataType(DataType.Password)]
    [Display(Name = "Password")]
    public string Password { get; set; }

}

It is working on services.AddLocalization(options => { options.ResourcesPath = "Resources"; }); but it doesn't work on AddSqlLocalization could you check it ?

suatsuphi commented 4 years ago

there is a problem on SqlStringLocalizer.cs and line 40 so I changed it

public LocalizedString this[string name, params object[] arguments]
        {
            get
            {
                var str = this[name];
                if (arguments.Length > 0)
                    str = this[string.Format(str, arguments.Select(x => x.ToString()).ToArray())];
                return str;
            }
        }

if string contain string format I mean this {} so it will work for string format. I think my logic will work