0

I am working a multi-lang site. I want to get and set culture and uiculture with culturename without countryname. If browser is english or lang is English choosen, it will return en not en-US or en-GB. Because I use one localresources file per language and I have to send language code to sql procedure as a parameter.

Thread.CurrentThread.CurrentCulture
 Thread.CurrentThread.CurrentCulture.Name
 Thread.CurrentThread.CurrentUICulture

All of them returns en-GB,de-DE,de-AT etc... I just want first part and use this ones. http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo%28VS.71%29.aspx There are the name in the link but browser does note return it, I just want and use the simple part. How can I do that?

It is solved (:

edit: Now, How can I read browser's culture and if I don't have it, how can I set the culture that I have. eg: I have en,de,ru and the visitor's browser sen me fr, I want it is shown en ?

1 Answers1

1

Have a look at the TwoLetterISOLanguageName-property. It should return the identifier you are looking for. For example:

var cult = new System.Globalization.CultureInfo("en-US").TwoLetterISOLanguageName;

Returns "en" so that you can send it to the stored procedures.

Markus
  • 20,838
  • 4
  • 31
  • 55
  • @user3318568: By default, the browser's culture should also be set in your application. If you want to set it in another way, see http://msdn.microsoft.com/en-us/library/bz9tc508.aspx. – Markus Feb 17 '14 at 10:42