I am new to .NET Core 6 and I have realized that several things should be done manually.
One of them is localization. For example, when using a simple action to change the user password, the message "Incorrect password." is returned in the errors collection when the old password mismatch.
I have spent a lot of time trying to localize that simple message so that it is shown in Spanish. I have read a lot of pages telling about this but none works. I think it is because this message is not a DataAnnotation
message.
When I used .NET Framework, all of these were made automatically since the resource DLL is always installed by default. It seems that in .NET Core 6 those DLL's are missing, or at least, they are vey hidden.
As an attempt, I added this to Program.cs file:
builder.Services.AddMvc()
.AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix, options => options.ResourcesPath = "Resources")
.AddDataAnnotationsLocalization();
builder.Services.AddLocalization(options => options.ResourcesPath = "Resources");
builder.Services.Configure<RequestLocalizationOptions>(options =>
{
var supportedCultures = new[] { new CultureInfo("en"), new CultureInfo("es") };
options.DefaultRequestCulture = new RequestCulture("es");
options.SupportedCultures = supportedCultures;
options.SupportedUICultures = supportedCultures;
});
app.UseRequestLocalization();
And also added a file "Resouces\ErrorMessages.es.resx" with an entry whose key is PasswordMismatch
with the message in Spanish, but no avail.
Any help, please?