0

I have set arabic as as client's machine language.But in C# program while am using

var test = Thread.CurrentThread.CurrentCulture;

It shows the language as En-US.?
How i get the selected language of the machine?.

शेखर
  • 17,412
  • 13
  • 61
  • 117
user2156088
  • 2,350
  • 5
  • 20
  • 24

2 Answers2

1

This will depend on how the client browser is configured. If the client browser's default language is configured to be en-US you will never be able to get the actual language on the server. For example in Google Chrome there's a setting where you could specify the preferred languages sent to the server:

enter image description here

So once you have configured the preferred language of your web browser to be something else, the browser will send this language as Accept-Language HTTP request header and you will be able to retrieve it on the server. In this case ASP.NET will automatically assign it to the current thread's culture assuming in your web.config you have not changed it in the <globalization> element but left the default value.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
0

Request.UserLanguages is the property you're looking for.
Just keep in mind that this array may contain arbitrary (even non-exsitent) languages as set by request headers.

Example:

var lobUserLanguages = Request.UserLanguages;
CultureInfo ci;
if (lobUserLanguages.Count > 0)
{
    try
    {
        ci = new CultureInfo(lobUserLanguages[0]);
    }
    catch(CultureNotFoundException)
    {
         ci = CultureInfo.InvariantCulture;
    }
}
else
{
    ci = CultureInfo.InvariantCulture;
}
शेखर
  • 17,412
  • 13
  • 61
  • 117