I following this documentation to implement the localization inside my ASP.NET Core application, and I'm trying to display in the footer a select which contains all the languages supported by my app.
So I created a file called _SelectLanguagepartial as suggested by the documentation:
@using Microsoft.AspNetCore.Builder
@using Microsoft.AspNetCore.Http.Features
@using Microsoft.AspNetCore.Localization
@using Microsoft.AspNetCore.Mvc.Localization
@using Microsoft.Extensions.Options
@inject IViewLocalizer Localizer
@inject IOptions<RequestLocalizationOptions> LocOptions
@{
var requestCulture = Context.Features.Get<IRequestCultureFeature>();
var cultureItems = LocOptions.Value.SupportedUICultures
.Select(c => new SelectListItem { Value = c.Name, Text = c.DisplayName })
.ToList();
var returnUrl = string.IsNullOrEmpty(Context.Request.Path) ? "~/" : $"~{Context.Request.Path.Value}";
}
<div title="@Localizer["Request culture provider:"] @requestCulture?.Provider?.GetType().Name">
<form id="selectLanguage" asp-controller="Language"
asp-action="SetLanguage" asp-route-returnUrl="@returnUrl"
method="post" class="form-horizontal" role="form">
<label asp-for="@requestCulture.RequestCulture.UICulture.Name">@Localizer["Language:"]</label>
<select name="culture" onchange="this.form.submit();"
asp-for="@requestCulture.RequestCulture.UICulture.Name"
asp-items="cultureItems"></select>
</form>
</div>
and I load this in the footer in the following way:
@await Html.PartialAsync("_SelectLanguagePartial")
this works well, but the problem is that I get only the italian language, but I should get instead also the english, infact, inside the Configure method I specified these languages:
var supportedCultures = new[]
{
new CultureInfo("it-IT"),
new CultureInfo("en-EN")
};
app.UseRequestLocalization(new RequestLocalizationOptions
{
DefaultRequestCulture = new RequestCulture("it-IT"),
SupportedCultures = supportedCultures,
SupportedUICultures = supportedCultures
});
as you can see I set as default language the italian but I have also the english language, I tried also to edit in en-US but in the select I get only the italian language.
What I did wrong?