ASP.Net - Make Page.Uiculture return culture in "en-BR" format

Asked

Viewed 308 times

2

Was defined in the Web.config globalization:

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

However, when I read the Page.UICulture get back to me "Portuguese (Brasil)", I want you to return the code "en". Is there a conversion method? Do if is not a solution I would like to use.

2 answers

2


I found a solution:

Thread.CurrentThread.CurrentUICulture.Name

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

1

To recover the user’s browser language 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 so in my initial load, here I work with systems for 3 countries.

One more option to work.

  • Thank you so much Alexsandro, your reply was very helpful for something else I needed to do hehe!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.