Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Setting custom Displayname (shortening name) for SupportedUICulture

$
0
0

Hi guys,

From the below code, the view displays full name of cultures by default.

@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 asp-controller="Home" asp-action="SetLanguage"
          asp-route-returnUrl="@returnUrl"
          method="post" class="form-horizontal">
        @Localizer[""] <select id="forlang" style="max-width: 42px" name="culture" onchange="this.form.submit();"
                                        asp-for="@requestCulture.RequestCulture.UICulture.Name"
                                        asp-items="cultureItems"></select></form></div>

How can I make it so that items of select dropdown would display the cultures like I want to see. In other words, I don't want to have such a long culture names (for ex. "English (United Kingdom)") in my view, but shot names like in most of websites (for ex. "en").

Thanks in advance!


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>