6

I rephrase another question I asked earlier.

I have a basic C# Asp.net MVC 5 application. I create an account through the following code (provided by the template in Vs 2013)

protected async Task<bool> CreateAccountAndAddRoleAsync(UserManager<ApplicationUser> userManager, ApplicationUser user, string password, string role)
{
    var result = await userManager.CreateAsync(user, password);

     if (result.Succeeded)
     {
          try
          {
              var roleResult = await userManager.AddToRoleAsync(user.Id, role);
              if (roleResult.Succeeded)
              {
                   //await SignInAsync(userManager, user, isPersistent: false);
                   return true;
              }
           }
           catch (Exception e)
           {
               Console.WriteLine(e);
              throw;
           }
     }
     AddErrors(result);
     return false;
}

protected void AddErrors(IdentityResult result)
{
   foreach (var error in result.Errors)
   {
       ModelState.AddModelError("", error);
   }
}

The problem is that when the username is already taken (or any other error message), the messages are in English. Such as

Name xxx is already taken

Instead of

L'identifiant xxx est déjà utilisé

The problem is that the message is provided by the framework with

var result = await userManager.CreateAsync(user, password);

And the AddErrors(result); enumerates the messages (in english) to display them to the user. How can I modify the messages?

I changed the culture in the webconfig file with

<globalization uiCulture="fr-FR" culture="fr-FR" />

But I still have an English message. In fact, the real problem is that I can't change the message provided by the framework even if I wanted another message in English.

Does anyone know how to change the message provided by the IdentityResult ?

Hakan Fıstık
  • 16,800
  • 14
  • 110
  • 131
Daniel
  • 9,312
  • 3
  • 48
  • 48
  • Install the French .NET language pack on the server? – GSerg Oct 02 '14 at 14:14
  • 3
    Check out this thread: http://stackoverflow.com/questions/19961648/how-to-localize-asp-net-identity-username-and-password-error-messages. Latest comment from the ASP.NET developer was posted just yesterday. Short answer is: these messages are not localizable right now. – Andrei Oct 02 '14 at 14:18
  • Thanks Andrei! I think I will do it dirty then.... – Daniel Oct 02 '14 at 14:22
  • check this if you need to override error messages in your language. https://stackoverflow.com/questions/27655578/how-can-customize-asp-net-identity-2-username-already-taken-validation-message – Iman Sep 12 '17 at 07:31

1 Answers1

7

Do not forget to install your language package from nuget for example:

Install-Package Microsoft.AspNet.Identity.Core.ru
Dovlet Mamenov
  • 581
  • 1
  • 7
  • 20