How to use UseRequestLocalization in ASP .Net Core 3?
Asked Answered
C

1

8

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,        
});
Colum answered 13/7, 2019 at 7:17 Comment(0)
B
3

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"));
                }))
        );
Borderline answered 31/3, 2020 at 20:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.