localizationasp.net-coreasp.net-core-localization

Cannot set default and only culture in ASP.Net Core app


I'm working on Polish operating system:

In my Statup.csclass I have following code

        // Configure the localization options
        var supportedCultures = new[]
        {
            new CultureInfo("en-GB")
        };

        app.UseRequestLocalization(
            new RequestLocalizationOptions
            {
                DefaultRequestCulture = new RequestCulture("en-GB"),
                SupportedCultures = supportedCultures,
                SupportedUICultures = supportedCultures,
                FallBackToParentCultures = true,
                FallBackToParentUICultures = true,
                RequestCultureProviders = null
            });

The full options are for reference only to be sure that nothing is set behind. In my _Layout.cshtml I have following code:

<div>Current Culture: @CultureInfo.CurrentCulture.DisplayName</div>
<div>Current UI Culture: @CultureInfo.CurrentUICulture.DisplayName</div>

The only supported and available culture should be en-GB, however on web site it is always showing:

Current Culture: Polski (Polska)
Current UI Culture: Polski (Polska)

I've tried to add Microsoft.AspNet.Localization package, but it makes no difference. Based on code in localization middleware, all should work as expected. I'm running latest version of ASP.NET Core 1.0.0.


Solution

  • There is one important thing, not mentioned in documentation. UseRequestLocalization has to be placed before UseMvc, mine was below.