I need to have a multi-language web application. I was using my code in .net core 2.2 and everything was good. When I migrated to .net core 3 I face to some issues that one of them was using UseRequestLocalization.
I'm using this code in Configure method of startups.cs and after the running project, I see an empty page.
var supportedCultures = new CultureInfo[] {
new CultureInfo ("en-US"),
new CultureInfo ("en"),
GetPersianCulture ("fa-IR"),
GetPersianCulture ("fa"),
};
app.UseRequestLocalization(new RequestLocalizationOptions
{
DefaultRequestCulture = new RequestCulture("fa"),
SupportedCultures = supportedCultures,
SupportedUICultures = supportedCultures,
});
Declaration of supported languages is defined in Configure() of your Startup class (see example). If you still need all accepted languages as a simple string[] like the older Request. UserLanguages property, then use the HeaderDictionaryTypeExtensions. GetTypedHeaders() extension defined in the Microsoft.
Middleware is software that's assembled into an app pipeline to handle requests and responses. Each component: Chooses whether to pass the request to the next component in the pipeline. Can perform work before and after the next component in the pipeline.
Issue with globalization asp.net core 3.1, that's how I solved it
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
var supportedCultures = new string[] { "en-GB", "en-US" };
app.UseRequestLocalization(options =>
options
.AddSupportedCultures(supportedCultures)
.AddSupportedUICultures(supportedCultures)
.SetDefaultCulture("en-GB")
.RequestCultureProviders.Insert(0, new CustomRequestCultureProvider(context =>
{
return Task.FromResult(new ProviderCultureResult("en-GB"));
}))
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With