.UICulture page - How to get a UICulture code with two letters?

In ASP.NET web forms, setting UICulture = "en" in the @Page Response.Write (Page.UICulture) directive returns the string "English" instead of the two letter code "ru" .

Is this the only way to return the name of two letters with this?

CultureInfo.CurrentUICulture.TwoLetterISOLanguageName

Or is there a better / more elegant way?

+3
source share
1 answer

Honestly, I don't know a better way to do this.

You can create an extension method, but this may be redundant:

public static class Extensions
{
    public static string GetUICultureCode(this System.Web.UI.Page page)
    {
        return System.Globalization.CultureInfo.CurrentUICulture.TwoLetterISOLanguageName;
    }
}

this.GetUICultureCode()

+3

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


All Articles