'How to translate IdentityResult error messages to Swedish when using Identity.EntityFramework
I need to translate the error messages of IdentityResult using Microsoft.AspNet.Identity.EntityFramework to swedish. There are no available libraries to help solve this. Do I need to override Identity classes instead? Any good solution?
Here is an example code:
public async Task<ActionResult> RegisterUser(RegisterUserViewModel model)
{
if (ModelState.IsValid)
{
var user = new ApplicationUser { UserName = model.UserId, Email = model.Email };
var result = await UserManager.CreateAsync(user);
if (result.Succeeded)
{
//save the user
}
else
{
//errors can contain messages like The user email is already or The username is already taken
foreach (var error in result.Errors)
{
ModelState.AddModelError("", error); //translate the error
}
}
}
return View(model);
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
