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?.
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?.
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:
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.
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;
}