The language of the main language .NET.NET is always English

I set the localization as described on the Microsoft blog, but the default language is always English. Here's what my Startup.cs looks like in terms of localization.

CultureInfo[] supportedCultures = new[]
            {
                new CultureInfo("ar"),
                new CultureInfo("en") 
            };

In the ConfigureServices method:

    services.Configure<RequestLocalizationOptions>(options =>
        {
            options.DefaultRequestCulture = new RequestCulture("ar", "ar");
            options.SupportedCultures = supportedCultures;
            options.SupportedUICultures = supportedCultures;
        });
        services.AddLocalization(options =>
        {
            options.ResourcesPath = "Resources";
        });


        services.AddMvc()
        .AddViewLocalization()
        .AddDataAnnotationsLocalization();

In Configure mode:

        app.UseRequestLocalization(new RequestLocalizationOptions()
        {
            DefaultRequestCulture = new RequestCulture("ar"),
            SupportedCultures = supportedCultures,
            SupportedUICultures = supportedCultures
        });

Thank:)

+4
source share
1 answer

You set "Arabic" as DefaultRequestCulture, but it is DefaultRequestCultureused if none of the built-in providers can define the request culture. Default Providers:

  • QueryStringRequestCultureProvider
  • CookieRequestCultureProvider
  • AcceptLanguageHeaderRequestCultureProvider

Most likely, the culture is determined from the Accept-Language HTTP header that the browser sends.

AcceptLanguageHeaderRequestCultureProvider, DefaultRequestCulture. RequestCultureProviders RequestLocalizationOptions . Startup.cs:

public void ConfigureServices(IServiceCollection services)
{
    CultureInfo[] supportedCultures = new[]
    {
        new CultureInfo("ar"),
        new CultureInfo("en")
    };

    services.Configure<RequestLocalizationOptions>(options =>
    {
        options.DefaultRequestCulture = new RequestCulture("ar");
        options.SupportedCultures = supportedCultures;
        options.SupportedUICultures = supportedCultures;
        options.RequestCultureProviders = new List<IRequestCultureProvider>
        {
            new QueryStringRequestCultureProvider(),
            new CookieRequestCultureProvider()
        };
    });
}

Configure app.UseRequestLocalization(); app.UseMvc();

+7

Source: https://habr.com/ru/post/1678973/


All Articles