asp.netglobalizationcultureinfoculturecurrentuiculture

Asp.Net Culture name without region/country name and default settings


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 ?


Solution

  • 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.