ASP.Net - Make Page.UICulture return culture in "pt-BR" format

2

Globalization was defined in Web.config

:

<globalization requestEncoding="utf-8" responseEncoding="utf-8" culture="pt-BR" uiCulture="pt-BR"/>

However, when I read Page.UICulture , I get "Português (Brasil)" , I want to return the code "en-pt" . Is there any conversion method? Making if is not a solution I'd like to use.

    
asked by anonymous 24.07.2017 / 15:00

2 answers

2

I found a solution:

Thread.CurrentThread.CurrentUICulture.Name

This property returns me the language code in the format I want.

    
24.07.2017 / 15:09
1

To retrieve the language of the user's browser I always use, as follows:

List<string> Idiomas = new List<string>() { "pt-BR", "es-MX", "en-US" };
string cultureInfo;
try
{

    var userLanguages = Request.UserLanguages;
    if (Idiomas.Contains(userLanguages[0]))
    {
        cultureInfo = userLanguages[0];
    }
    else
    {
        cultureInfo = "pt-BR";
    }
}
catch
{
    cultureInfo = "pt-BR";
}
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(cultureInfo);

I use this in my initial load, here I work with systems for 3 countries.

One more option to work on.

    
24.07.2017 / 18:08