ASP.Net core features new support for localization.
In my project I need only one language. For most of the text and annotations I can specify things in my language, but for text coming from ASP.Net Core itself the language is English.
Examples:
- Passwords must have at least one uppercase ('A'-'Z').
- Passwords must have at least one digit ('0'-'9').
- User name 'x@x.com' is already taken.
- The E-post field is not a valid e-mail address.
- The value '' is invalid.
I've tried setting the culture manually, but the language is still English.
app.UseRequestLocalization(new RequestLocalizationOptions
{
DefaultRequestCulture = new RequestCulture("nb-NO"),
SupportedCultures = new List<CultureInfo> { new CultureInfo("nb-NO") },
SupportedUICultures = new List<CultureInfo> { new CultureInfo("nb-NO") }
});
How can I change the language of ASP.Net Core, or override its default text?
For those who are wondering, if it is possible to localize the messages for currently chosen culture, yes it is possible. In asp.net core 2.2 you can create a class LocalizedIdentityErrorDescriber where IdentityResources is the name of your dummy class (it is described here: Globalization and localization):
Then create resource files for your languages as followed: Resources\(name of dummy class described above)(.culture).resx. For your default language culture should be left blank. And don't forget about the "." before culture name if it is not default. Your IdentityResources files should look like this:
In Startup.cs add the following lines:
By now you are almost done but you will need to set Culture cookie and there is a code example in here: Globalization and localization. Hope it helps someone.